Is there anyway to get the inner type parameter of a field using reflection
For Ex:
public final class Main
{
class A
{
public int aX;
public String aS;
}
class B
{
public Set<A> bSet;
}
public static void main(String[] args)
{
Class clazz = B.class.getField("bSet").getType();
}
};
Using the above I can only get “Set” is there anyway I could get A as well ?
Thanks
Reflection can indeed deliver full parameterized types for fields (and classes, etc). It’s only objects that have their types erased at runtime.
Call
getGenericTypeinstead ofgetTypeand start reading javadoc.