previous | start | next

## Generic Types

- A generic type has one or more type variables
- Type variables are instantiated with class or interface types
- Cannot use primitive types, e.g. no `ArrayList<int>`
- When defining generic classes, use type variables in definition:

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

- NOTE: If `S` a subtyoe of `T`, `ArrayList<S>` is not a subtype of `ArrayList<T>`.

previous | start | next