Subject: Parameterized types versus high-performance Java

From: "C. van Reeuwijk" <[email-masked]>
Date: Wed, 2 Feb 2000 18:10:20 +0100

Hello everyone,

As you probably know, there is discussion in the Java community about
adding generic types to Java in one form or another. There have been
several papers that propose such a feature, and there has been some
talk from Sun that they are interested in adding it.

What you perhaps don't know is that things have progressed quite a bit
beyond that. First, there has been an official proposal through the
`community process' to add this feature, see

<http://java.sun.com/aboutJava/communityprocess/jsr/jsr_014_gener.html>

Note that the author of that proposal is Gilad Bracha, who works as
'Computational Theologist' at Sun Microsystems. See

<http://java.sun.com/people/gbracha>

for an explanation of the job description.

Recently I've learned that things have progressed beyond that. There
has been an article in Dr Dobbs:

<http://www.ddj.com/articles/2000/0002/0002a/0002a.htm>

and there are rumors that it is already available in JDK 1.3. It
is said that that if you do 

% java com.sun.tools.javac.GJMain <filename>.java

You get a Java compiler that supports generics. (Since I don't have a
Windows machine handy right now, I cannot easily confirm this.) This
makes some sense, given the sentence in the DDJ article

   Odersky's GJ compiler is also the basis of Sun's current Java compiler,
   although that compiler does not support generics (yet).

I am worried by these developments, because I don't think GJ is a very
suitable language extension for high-performance Java, for the following
reasons:

1. Only reference types are allowed as parameters; primitive types,
or simple values such as integer constants, are not allowed. This means
for example that the multidimensional arrays that have been proposed within
Java Grande cannot be expressed as generic type.

2. The GJ extensions only add a layer of type checking to exisiting
container classes such as java.lang.Vector. In the resulting bytecode
the existing containers are still used.

It is not at all clear how typeless containers can be implemented
efficiently, and due to compatibility with legacy code it is not clear
if a smart compiler can use an alternative implementation, even if
it bypasses bytecode.

For the sake of completeness I should mention that we are working on
our own set of Java extensions. That set also contains generic types,
although in our case it *is* allowed to have primitive types and
constants as parameter. See
<http://www.pds.twi.tudelft.nl/timber/spar/templates.html>
<http://www.pds.twi.tudelft.nl/timber/spar/array_interface.html>

Comments, anyone?

-- 
Kees van Reeuwijk, Delft University of Technology
http://www.pds.twi.tudelft.nl/~reeuwijk