Java is being augmented with a library of interfaces and classes.
Already there are several abstractions in the library that
would be more useful if parameterization were available.
Types such as Vector
and Enumeration
are most naturally written as
parameterized types, but currently manipulate objects of type Object
instead.
This has two unfortunate consequences:
int
then it is necessary to
objectify them. For example, int
must be
explicitly wrapped in an Integer
object to make it usable as an Object
.
This wrapping step is awkward for the programmer and has runtime overhead.
Vector
or produced by
an Enumeration
, it
must be explicitly cast from Object
to the expected type. If the element
has a primitive type, it also must be unwrapped after the cast,
adding even more cost and coding complexity.
Both problems are ameliorated by parameterized types. When elements are added, there is no need to objectify them, and when they are retrieved from the collection, there is no need for the expensive runtime cast or unwrapping.