21.7 Raw Types
The test programs for generic class Stack
in Section 21.6 instantiate Stack
s with type arguments Double
and Integer
. It’s also possible to instantiate generic class Stack
without specifying a type argument, as follows:
In this case, the objectStack
is said to have a raw type, which means that the compiler implicitly uses type Object
throughout the generic class for each type argument. Thus the preceding statement creates a Stack
that can store objects of any type. This is important for backward compatibility with prior versions of Java. For example, the data structures of the Java Collections Framework (see Chapter 20) all stored ...
Get Java How to Program (early objects), 9/e 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.