previous | start | next

## Wildcards

- Typical example--start with

      public static <E extends Comparable<E>> E getMax(ArrayList<E> a)
      {
         E max = a.get(0);
         for (int i = 1; i < a.size(); i++)
            if (a.get(i).compareTo(max) > 0) max = a.get(i);
         return max;
      }

- `E` extends `Comparable<E>` so that we can call `compareTo`
- Too restrictive--can't call with `ArrayList<GregorianCalendar>`
- `GregorianCalendar` does not implement `Comparable<GregorianCalendar>`, only `Comparable<Calendar>`
- Wildcards to the rescue:

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

previous | start | next