title: Java :How Generic Erasure Works
body: <blockquote>
  <p>Scenario A.java-----------after erasure--------&gt;M.class</p>
  <p>Scenario B.java-----------after erasure--------&gt;M.class</p>
  </blockquote>
  <p>Then why A is illegal and B is legal since they have almost the same M after erasure.</p>
  <p>Scenario A before erasure:</p>
  <pre><code> class ArrayList&lt;V&gt; {
   private V[] backingArray;
           public ArrayList() {
               backingArray = new V[DEFAULT_SIZE]; // illegal
             }
   }
  </code></pre>
  <p>Scenario A after erasure:</p>
  <pre><code> class ArrayList&lt;V&gt; {   
     private Object[] backingArray;   
        public ArrayList() {
        backingArray = new Object[DEFAULT_SIZE]; // this is not useful   
     } 
  }
  </code></pre>
  <p>actually the Object[Default_Size] is useful ~
  Scenario B before erasure:</p>
  <pre><code>class ArrayList&lt;V&gt; {
    private V[] backingArray;
    public ArrayList() {
      backingArray = (V[]) new Object[DEFAULT_SIZE]; 
    }
  }
  </code></pre>
  <p>Scenario B after erasure:</p>
  <pre><code>class ArrayList&lt;V&gt; {
    private Object[] backingArray;
    public ArrayList() {
      backingArray = (Object[]) new Object[DEFAULT_SIZE]; 
    }
  }
  </code></pre>