title: Java : How to get type of List<?>
body: <p>I'm working on reflection in java.
  I know this is a common question and there are a lot of articles about it but I'm a bit confused and can't seem to find the right solution for what I'm trying to achieve.</p>
  
  <p>I have :</p>
  
  <pre><code>public class ClassA {
      private List&lt;?&gt; myList;
      // getters, setters
  }
  </code></pre>
  
  <p>"myList" will contain a list of objects (DTOs) :</p>
  
  <pre><code>List&lt;?&gt; myList; // could be List&lt;DTO1&gt; or List&lt;DTO2&gt; ...
  </code></pre>
  
  <p>I'm trying to get the type of the list from another class like this :</p>
  
  <pre><code>public class ClassB {
      public void myMethod() {
          // get type of ClassA.getMyList()
      }
  }
  </code></pre>
  
  <p>I can only get "ArrayList" when I try using stuff like getClass(), getType()...
  Trying to get the class of an element in the list results in "LinkedHashMap".</p>
  
  <p>I really want to achieve this by using a wildcard type for the list.</p>
  
  <p>So is there a way I can get the type of myList with minimal code ?</p>
  
  <hr>
  
  <p>EDIT :</p>
  
  <p>Thank you all for your answers.</p>
  
  <p>Just one thing : <code>myList</code> contains elements of type <code>LinkedHashMap</code>, this wasn't very clear on my post.</p>
  
  <p>It seems this really can't be done. Each <code>LinkedHashMap</code> represents an object but you can't know which one. They are just a list of keys + values.</p>