I have a list like that:
private List<T> myList = new ArrayList<T>();
I want to get the .class of T. How can I do that?
I mean as like:
myList.getClass()
EDIT: I tried that:
Field genericField = Wrapper.class.getDeclaredField("myList");
ParameterizedType genericType = (ParameterizedType) genericField.getGenericType();
Class<?> genericClass = (Class<?>) genericType.getActualTypeArguments()[0];
and when I debug it
genericType
has a value of:
java.util.List
so I think that this is certainly different issue from that question: Get generic type of java.util.List because of if you declare a class with T
and assign something to T
later at another method, class that T
holds disappear.