Next: 2.2.1 Using class Object
Up: 2. Generics and Multiple
Previous: 2.1.0.3 Java.
2.2 Approximating Generics in Java
A class is an implementation of a data type.
The ``container'' data types (such as the Set, the List,
the Tree, etc)
can be parameterized with respect to the element type in order to model
homogeneous data structures, which contain just one type of
elements (and its subtypes).
In some situations, the element type may be partially constrained. For
instance, a Dictionary type may require the elements to be from a
LinearOrder type. The templates in C++, the generics in Eiffel and
Ada-95, the functors in SML [33], etc all support convenient
implementation of such types (resp. subprograms) as parameterized
classes (resp. routines). These parameterized modules are instantiated
before use by binding types to generic type parameters.
Java does not support any construct akin to templates/generics. An
extension to the Java language and the Java Virtual Machine is proposed
in [28] to incorporate templates in their full glory. Pizza
[29] and GJ [4] are supersets of Java which support
parametric polymorphism that can be translated into pure Java.
Here we review and analyze two idioms to approximate generic modules:
one that uses the class Object or other reference types as a
generic element type and another that uses reflection.
Next: 2.2.1 Using class Object
Up: 2. Generics and Multiple
Previous: 2.1.0.3 Java.
T. K. Prasad