What Generic Code Looks Like

There are three parts to generics:

  1. Declare the class which will have generic type parameters

  2. Declare/instantiate an object of that class, passing the actual type arguments to it.

  3. Invoke methods on the object of the instantiated generic class.

Using the instantiated generic class is no different to using a non-generic class, so we won't spend a lot of time looking at that. The class declaration has to come before any instantiations, so let's look at declarations first.

Get Just Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.