Java with Parameterized Types

Download the source code for PolyJ version 1.0.2
Download the precompiled Win32 version of PolyJ version 1.0.2
PolyJ is a portable compiler that accepts an extended version of the Java language. PolyJ 1.0.2 was released in July 2000; use the links above to download it. The 1.0.2 release, supporting Windows NT, was produced by researchers at Cornell University. Work on new releases of PolyJ continues at Cornell. The original PolyJ language and compiler were developed by the Programming Methodology Group at the MIT Laboratory for Computer Science. There is a PolyJ FAQ containing answers to common questions about PolyJ. There is also a manual page for the PolyJ compiler.

The Language

The PolyJ language includes support for generic programming in the form of parameterized types. PolyJ provides constrained parametric polymorphism, like some other proposals for adding genericity to Java. Unlike some, it use signature constraints, which provide flexibility when composing a program. PolyJ also allows all types to be used as parameters, even basic types like int. Another powerful feature is that instantiation types and parameter types are first-class types that may be used wherever a type may be used -- particularly, in safe run-time casts and with "instanceof". See the FAQ for more details on these issues.

The PolyJ language is defined in a paper appearing in POPL'97. Almost all of the language defined there is now implemented. We are considering further extensions.

Compatibility

PolyJ is easy to fit into an existing Java development environment, since it is backwards compatible with Java. Since PolyJ works by translation, it has several nice compatibility properties:

Implementation

The compiler is built as an extension to the guavac compiler developed by David Engberg. It is written in C++. Because it is built on a version of guavac that does not support inner classes, the current PolyJ compiler does not either. However, future releases of PolyJ will be implemented in Java and will support inner classes and other extensions.

The PolyJ compiler works by translating PolyJ code into corresponding Java code, in a manner sketched in the POPL'97 paper. In this translation, we avoid the code expansion associated with implementations of the C++ template mechanism. The PolyJ compiler generates very little extra code for each instantiation of a parameterized abstraction. In the translation, the code of a parameterized class is translated into a similar Java class. For each instantiation, a small trampoline class is generated to glue the generic code to its parameters. The translation uses only very straightforward, well-supported Java features. It does not use the Java Reflection API and it does not require an extended JVM. The translation imposes a small or negligible performance overhead for most programs.

Documentation

Current PolyJ contributors

Andrew Myers
Barbara Liskov
Jed Liu
Grant Wang
Nick Mathewson

Send us comments!
Click to receive email
when this page changes
* Powered by NetMind *