GJ Extending the Java programming language with type parameters

GJ Extending the Java programming language with type parametersSay you wish to process collections. Some may be collections of bytes, others collections of strings, and yet others collections of collections of strings. The Java programming language supports such variation by allowing you to form a collection of Object, so the elements may have any reference type. In order to keep the language simple, you are forced to do some of the work yourself: you must keep track of the fact that you have a collection of bytes, and when you extract an element from the collection you must cast it to class Byte before further processing.

This situation is becoming more common as the Java platform evolves, notably with the addition of collection classes to JDK 1.2. Other languages provide additional support for this situation: in C++, it is supported with templates; in Ada, it is supported with generics; and in ML and Haskell, it is supported with parametric polymorphism.
This note proposes GJ, an extension to the Java programming language that supports types with parameters. GJ programs look much like the equivalent Java programs, except they have more type information and fewer casts. The semantics of GJ is given by a translation into the Java programming language. The translation erases type parameters, replaces type variables by their bounding type (typically Object), adds casts, and inserts bridge methods so that overriding works properly. The resulting program is pretty much what you would write if generics weren’t available. The translation is designed so that new GJ code will work with existing Java libraries, even when the libraries are available only in binary class file form.

Website: homepages.inf.ed.ac.uk | Filesize: 153kb
No of Page(s): 25
Click here to download GJ Extending the Java programming language with type parameters

Related Tutorial

Tags: , , , ,

Comments

Leave a Reply