Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get (and use)the generic type from a Class at runtime.

843793Oct 26 2009 — edited Oct 26 2009
I need to instantiate and object with a generic parameter, representing the generic type of one of the members of an object. Best explained with an example:
Class ExampleClass {
	Class someClass;
	public void setSomeClass(Class c) {
		this.someClass=c;
	}
}
new ExampleClass().setSomeClass(Integer.class);
How do I now instantiate an ArrayList for example with the generic type (<Integer>) of ExampleClass.someClass?

Thank you
nat
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 23 2009
Added on Oct 26 2009
7 comments
129 views