How can I access the class object for Generics?
I am currently doing this as follows:
List<String> list= new ArrayList<String>(); list.getClass();
This is normal? Or what should be the way?
This will return the same as ArrayList.class. Java generators erase the generic type at runtime; in other words, from a "list" you will never know that the type of an element is String. There's a great FAQ on this in
http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html
, , . , (, /), . , .
, java.lang.reflect.Method , . getGenericReturnType(). java.lang.reflect.Type, Class, ParameterizedType WildcardType, . . , instanceof , , .
java.lang.reflect.Method
java.lang.reflect.Type
Class
ParameterizedType
WildcardType
instanceof
, , ( , ). , .