title: type erasure in implementation of ArrayList in Java
body: <p>I was reading this article on <a href="http://www.ibm.com/developerworks/library/j-jtp01255/index.html" rel="nofollow">Java Generics</a> and there it is mentioned that the constructor for an <code>ArrayList</code> looks somewhat like this:</p>
  
  <pre><code>class ArrayList&lt;V&gt; {
    private V[] backingArray;
    public ArrayList() {
      backingArray = (V[]) new Object[DEFAULT_SIZE]; 
    }
  }
  </code></pre>
  
  <p>I was not able to understand how type erasure and type checking by the compiler happens as explained there. One point I got was that the type parameter is transformed to <code>Object</code> type.</p>
  
  <p>I would imagine it as (replacing all <code>V</code> with <code>Object</code>), but this definitely wrong.</p>
  
  <pre><code>class ArrayList&lt;Object&gt; {
        private Object[] backingArray;
        public ArrayList() {
          backingArray = (Object[]) new Object[DEFAULT_SIZE]; 
        }
  }
  </code></pre>
  
  <p>How exactly is it transformed to <code>Object</code> type but still retaining the type safety for <code>V</code>?
  when I have <code>ArrayList&lt;String&gt;</code> and <code>ArrayList&lt;Integer&gt;</code> are there two different classes for each? If not, where is the type information of <code>String</code> and <code>Integer</code> is stored?</p>