previous | start | next

## Type Erasure

- Virtual machine does not know about generic types
- Type variables are erased--replaced by type bound or `Object` if unbounded
- Ex. `ArrayList<E>` becomes

      public class ArrayList
      {
         public Object get(int i) { . . . }
         public Object set(int i, Object newValue) { . . . }
         . . .
         private Object[] elementData;
      }

- Ex. `getmax` becomes

      public static Comparable getMax(ArrayList a)
         // E extends Comparable<? super E> erased to Comparable

- Erasure necessary to interoperate with legacy (pre-JDK 5.0) code

previous | start | next