How to find the class object of Java generic type?

Posted by Samuel Yung on Stack Overflow See other posts from Stack Overflow or by Samuel Yung
Published on 2010-05-28T13:49:44Z Indexed on 2010/05/28 13:51 UTC
Read the original article Hit count: 174

Filed under:
|
|

Assume I have a generic type P which is an Enum, that is <P extends Enum<P>>, and I want to get the Enum value from a string, for example:

String foo = "foo";
P fooEnum = Enum.valueOf(P.class, foo);

This will get a compile error because P.class is invalid. So what can I do in order to make the above code work?

© Stack Overflow or respective owner

Related posts about java

Related posts about generics