title: Get generic array class
body: <p>I have a function:</p>
  
  <pre><code>add(Collection&lt;?&gt; many)
  </code></pre>
  
  <p>I call it like this:</p>
  
  <pre><code>Collection&lt;NewClass&gt; awa = new ArrayList&lt;NewClass&gt;();
  add(awa)
  </code></pre>
  
  <p>How do I get the <code>&lt;?&gt;</code> type? in that function?</p>
  
  <p><code>many.getClass()</code> gives <code>ArrayList</code>.</p>
  
  <p>Why I need this? Trying to make a generic DAO method for adding a Collection of <code>&lt; ? &gt;</code>.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>tried like this:</p>
  
  <pre><code>public static void add(Collection&lt;?&gt; many)  {
      Type typeArg = ((ParameterizedType)Testing.class.getGenericSuperclass()).getActualTypeArguments()[0];
      System.out.println(typeArg);
  }
  
      Collection&lt;NewClass&gt; awa = new ArrayList&lt;NewClass&gt;();
  
  
      add(awa);
  </code></pre>
  
  <p>got error:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
  </code></pre>