Reflection for Class of generic parameter in Java?

Posted by hatboysam on Stack Overflow See other posts from Stack Overflow or by hatboysam
Published on 2012-06-22T22:07:57Z Indexed on 2012/06/25 15:16 UTC
Read the original article Hit count: 145

Filed under:
|
|
|

Imagine the following scenario:

class MyClass extends OtherClass<String>{

   String myName;
   //Whatever

}

class OtherClass<T> {

   T myfield;

}

And I am analyzing MyClass using reflection specifically (MyClass.class).getDeclaredFields(), in this case I will get the following fields (and Types, using getType() of the Field):

myName --> String
myField --> T

I want to get the actual Type for T, which is known at runtime due to the explicit "String" in the extends notation, how do I go about getting the non-genetic type of myField?

© Stack Overflow or respective owner

Related posts about java

Related posts about generics