title: Reflection for Class of generic parameter in Java?
body: <p>Imagine the following scenario:</p>
  
  <pre><code>class MyClass extends OtherClass&lt;String&gt;{
  
     String myName;
     //Whatever
  
  }
  
  class OtherClass&lt;T&gt; {
  
     T myfield;
  
  }
  </code></pre>
  
  <p>And I am analyzing MyClass using reflection specifically <code>(MyClass.class).getDeclaredFields()</code>, in this case I will get the following fields (and Types, using getType() of the Field):</p>
  
  <pre><code>myName --&gt; String
  myField --&gt; T
  </code></pre>
  
  <p>I want to get the actual Type for T, which is known at runtime due to the explicit "String" in the extends notation, how do I go about getting the non-genetic type of myField?</p>
  
  <p>EDIT RESOLVED:</p>
  
  <p>Seems like the answer is "you can't".    For those who may look at this question later I'd recommend using Jackson (I was trying to do this to generate JSON) and annotating your classes and fields in such a way so that Jackson is aware of the inheritance hierarchy and can automatically do what the correct answer below suggested.</p>