title: Java adding to a unknown type generic list
body: <p>I've come into something I haven't come across before in Java and that is, I need to create a new instance of say the ArrayList class at runtime without assigning a known type then add data to the list. It sounds a bit vague so here is an example:</p>
  
  <pre><code>Class&lt;?&gt; c = i.getClass();
  
  Constructor&lt;?&gt; con = ArrayList.class.getConstructor();
  ArrayList&lt;?&gt; al = (ArrayList&lt;?&gt;)con.newInstance();
  
  al.add("something");
  </code></pre>
  
  <p>Now the reason I'm doing this versus just using generics is because generics are already being used heavily and the "i" variable in this example would be given to use as type "?". I would really rather not throw in another generic as this would cause more work for the user and would be much less flexible in the end design. Is there any way to use something like below (Note: what is below doesn't work). Anyone have ideas?</p>
  
  <pre><code>ArrayList&lt;c&gt; al = (ArrayList&lt;c&gt;)con.newInstance();
  </code></pre>