Chapter 6
Generic Programming
Topics in This Chapter
You often need to implement classes and methods that work with multiple types. For example, an ArrayList<T>
stores elements of an arbitrary class T
. We say that the ArrayList
class is generic, and T
is a type parameter. The basic idea is very simple and incredibly useful. The first two sections of this chapter cover the simple part.
In any programming language with generic types, the details get tricky when you restrict or vary type parameters. For example, suppose you want to sort elements. Then ...
Get Core Java for the Impatient, 3rd 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.