Please could you explain how to get information about a the class T on the GenericsTest definition class?
For example in some way to do:
Class<T> clazz = T.class;
I know it doesn't compile. I have tested with:
public class GenericsTest<T extends Thread>
private Class classT;
GenericsTest () {
ParameterizedType paramType =
(ParameterizedType) (getClass().getGenericInterfaces()[0]);
this.classT = (Class) (paramType.getActualTypeArguments()[0]);
System.out.println("classT=" + classT);
}
public static void main(String[] args) {
GenericTests<Thread> b = new GenericTests<Thread>();
}
}
after execution, I get an java.lang.ClassCastException.
Please do you have any suggestion about getting the current value of T inside GenericsTest, for example: java.lang.Thread.class
Thank you,
David |