How can I access Class object for Generics?
Currently, I am doing it this way:
List<String> list= new ArrayList<String>(); list.getClass();
Is this OK? Or, what should be the way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That will return the same as ArrayList.class. Java generics erase the generic type at runtime; in other words, from ‘list’ you’ll never know the element type is String. There’s a great FAQ on this at
http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html