12.4 Generics
There are no favorites in my office. I treat them all with the same general inconsideration.
—LYNDON B. JOHNSON, 36th President of the United States.
As we mentioned earlier, beginning with version 5.0, Java allows class definitions to include parameters for data types. These parameters are called generics. This section gives a brief introduction to this topic. Programming with generics can be subtle and requires care. To do serious programming with generics, you may want to consult a more advanced text.
The Basics
Classes and methods can use a type parameter instead of a specific data type. When Generics allows you to parameterize a data type using such a class or method, a programmer plugs in any class type for the type parameter ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access