title: Java Reflection, why are the supertype type arguments preserved at runtime
body: <p>So java has type erasure, which deletes the type arguments (no generic types at runtime). Can someone explain why the supertype type arguments are preserved then?</p>
  
  <pre><code>class StringList extends ArrayList&lt;String&gt; {
      public Type getType() {
  
          Type[] typeArguments = ((ParameterizedType) this.getClass()
                  .getGenericSuperclass()).getActualTypeArguments();
          return typeArguments[0];
      }
  }
  </code></pre>
  
  <p><strong>What this means basically is</strong>:</p>
  
  <pre><code>new ArrayList&lt;String&gt;()// I cannot use reflection to find out the generified type String
  </code></pre>
  
  <p>but</p>
  
  <pre><code>new StringList()//I can use reflection to see the generic type String
  </code></pre>
  
  <p>So type erasure is for backwards compatibility, but why are the supertype type arguments preserved then? Is the metadata updated to support it?</p>
  
  <p>Why the one and not the other?</p>