CHAPTER 22

image

Generics

Generics refer to the use of type parameters, which provide a way to define methods, classes and interfaces that can operate with different data types. The benefits of generics is that they provide compile-time type safety, and that they eliminate the need for most type conversions.

Generic classes

Generic classes allow class members to use type parameters. Such a class is defined by adding a type parameter section after the class name, which contains a type parameter enclosed between angle brackets. The naming convention for type parameters is that they should consist of a single uppercase letter. Typically, the letter ...

Get Java Quick Syntax Reference 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.