Wildcard Parameters and Generic Methods

The final piece of generics relates to the interaction between generic type parameters and methods. Most of the generic features we have seen so far are intended for API and library programmers. The main thing regular programmers need to remember is that:

public class HashSet <E> { /*more code*/

means that (to use this class) you will declare and instantiate a HashSet to work with a specific type:

HashSet<Timestamp> ht = new HashSet<Timestamp>();

The generic features presented in this section are different. These features are intended for use by regular programmers. You'll need these features in your own code, when you use somebody else's generic class.

There are two main generic-related features ...

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.