title: How do I make a generic list in Java?
body: <p>I am looking to reinvent the wheel a little and create my own generic array-backed list class in Java similar to ArrayList. Yes I know this is silly, but it is an academic pursuit. The problem is that you cannot instantiate an array of a generic type</p>
  
  <pre><code>public class MySuperCoolList&lt;E&gt; {
     E[] array;
  
     public MySuperCoolList&lt;E&gt; () {
        array = new E[10]; // ERROR: cannot do this!
     }
  }
  </code></pre>
  
  <p>Surely there must be a solution to this problem because Java's ArrayList is doing the same thing. The question is, how? How can I instantiate an array of a generic type <code>E</code>? And how is it done in ArrayList (if anyone knows)?</p>