title: an example of type erasure and my understanding
body: <pre><code>private void readList(ArrayList list){
      list.add("Hello");
      list.add(2);
  }
  
  public void run(){
      setFont("Courier-24");
      ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
      readList(list);
      println("list = "+list);
      println("Type of list[1] = "+list.get(1).getClass());
  
  }
  </code></pre>
  
  <p><strong>Result:</strong><br/>
      list = [Hello, 2]<br/>
      Type of list[1]=class java.lang.Integer</p>
  
  <pre><code>public void run(){
      setFont("Courier-24");
      ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
      readList(list);
      println("list = "+list);
      println("Type of list[0] = "+list.get(0).getClass());
  
  }
  </code></pre>
  
  <p><br/>
  <strong>Result:</strong><br/>
      list = [Hello, 2]<br/>
      Exception in thread "Thread-2" java.lang.ClassCastException: <br/>
      java.lang.String cannot be cast to java.lang.Integer</p>
  
  <p>After reading something about <code>type erasure</code>, I've got my guess:<br/><br/>
  When I call <code>readList(list)</code>, it's actually adding things into list that is 'falsely' regarded as type <code>ArrayList</code> so there is no error(this is my understanding of so-called <code>type erasure</code>). But if I call <code>println("Type of list = "+list.get(0).getClass());</code> in <code>run()</code> there comes the error because <code>list[0]</code> is of type <code>String</code>(while <code>println("Type of list = "+list.get(1).getClass());</code> doesn't because list[1] is of type <code>Integer</code>). <br/><br/>
  Is it like some criminal escaped from crime scene at first (because he belongs to normal people and normal people has freedom), and later when police start to check everyone that was around then he got caught because he is a criminal in deep? </p>