title: How to find the class object of Java generic type?
body: <p>Assume I have a generic type <code>P</code> which is an Enum, that is <code>&lt;P extends Enum&lt;P&gt;&gt;</code>, and I want to get the Enum value from a string, for example:</p>
  
  <pre><code>String foo = "foo";
  P fooEnum = Enum.valueOf(P.class, foo);
  </code></pre>
  
  <p>This will get a compile error because <code>P.class</code> is invalid. So what can I do in order to make the above code work?</p>