February 2014
Beginner
1248 pages
62h 25m
English
Figure 20.7 declares a generic Stack class for demonstration purposes—the java.util package already contains a generic Stack class. A generic class declaration looks like a nongeneric one, but the class name is followed by a type-parameter section (line 5). In this case, type parameter T represents the element type the Stack will manipulate. As with generic methods, the type-parameter section of a generic class can have one or more type parameters separated by commas. (You’ll create a generic class with two type parameters in Exercise 20.8.) Type parameter T is used throughout the Stack class declaration to represent the element type. This example implements a Stack as an ArrayList.
Read now
Unlock full access