Java Arena

Module 44

Type parameters (generics)

Classes that take a type as a parameter, as ArrayList does in `ArrayList<String>`. A class with a type parameter T, used with different type arguments and the diamond, why a type argument must be a reference type (Integer, not int), several type parameters, a class that keeps a list of T, generic interfaces implemented for one type or kept generic, and what the compiler checks for you. MOOC section 12.1.

Steps

  1. Why type parameters
  2. One class, many types
  3. Several type parameters, and a list of T
  4. Generic interfaces
  5. Putting it together: what the compiler checks