Behold the power of parametric polymorphism

Adding generic types to Java could mean less coding and fewer

1 2 Page 2
Page 2 of 2

Generic types can be understood as subtrees in the class tree, rooted in the parameterized class, with additional child classes and interfaces for each instantiation. The interfaces are necessary because a particular instantiation of a generic type (for example, Cons<Integer>) should not only inherit from your parameterized class (Cons<T>), but also from the same instantiation of any parameterized superclass (List<Integer>). Fortunately, the multiple inheritance involved in this integration does not require any implementation inheritance, and therefore can be modeled by the existing Java interface inheritance mechanism. Notice, in particular, that, unlike Java arrays, there is no covariant relationship among the instantiated type parameters (for example, List<Cons<Integer>> is not a subclass of List<List<Integer>>). It is possible to enhance this integration model to support covariant subtyping. Since covariant subtyping is a useful feature in practice, we plan to add this feature to NextGen after the initial implementation is completed.

Conclusion

Given Sun's release of a JSR for adding generic types to Java, and the existence of several viable Java extensions that support generic types, it is likely that generic types will be part of Java in the near future. When used judiciously, they will provide programmers with improved safety guarantees and less development and maintenance costs. In a world where Java plays increasingly critical roles in embedded systems, ecommerce technologies, and even good old-fashioned monolithic software apps, these guarantees are sorely needed.

Eric Allen has a computer science and math degree from Cornell, and is currently a PhD graduate student in the programming language technology group at Rice University. His research concerns the development of formal semantic models of Java, and extensions of Java, both at source and bytecode levels. Currently, he is implementing a source-to-bytecode compiler for the NextGen programming language, and collaborating with an optimizing compiler team to develop a JVM that gets "hints" from the static compiler without sacrificing bytecode portability.

Learn more about this topic

1 2 Page 2
Page 2 of 2