Section 20.6 Generic Classes

• Generic classes provide a means for describing a class in a type-independent manner. We can then instantiate type-specific objects of the generic class.

• A generic class declaration looks like a nongeneric class declaration, except that the class name is followed by a type-parameter section. The type-parameter section of a generic class can have one or more type parameters separated by commas.

• When a generic class is compiled, the compiler performs erasure on the class’s type parameters and replaces them with their upper bounds.

• Type parameters cannot be used in a class’s static declarations.

• When instantiating an object of a generic class, the types specified in angle brackets after the class name are known ...

Get Java™ How To Program (Early Objects), Tenth Edition 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.