What Generic Code Looks Like
There are three parts to generics:
-
Declare the class which will have generic type parameters
-
Declare/instantiate an object of that class, passing the actual type arguments to it.
-
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.