A Generic Java Language Extension

How GJ and Pizza differ

GJ is based on previous work on Pizza, but there are a number of differences between the two.

  • Generally, the design requirements for Pizza and GJ are different. Pizza extends the Java programming language with several ideas from the functional language community, while GJ adds just one important idea -- generic types -- and provides a much closer fit to the Java programming language.

  • In addition to generic types, Pizza introduces first-class functions and algebraic data types with pattern matching. We omitted first-class functions from GJ because they have already been added to Java in the form of inner classes. (Pizza was designed before inner classes first appeared, in Java 1.1.) We omitted algebraic types from GJ because they are only important for manipulating trees, and other techniques like visitor patterns work almost as well.

  • Generics in GJ only apply to reference types. In GJ, you cannot use a base type such as int as a type parameter, while in Pizza base types are legal as type parameters.

  • The GJ compiler performs a very simple mapping into Java bytecodes, making it easy to interface GJ programs with Java programs and to apply reflection to GJ programs. The Pizza compiler performs a more involved translation which makes it harder to call Pizza from Java, or to use reflection on Pizza programs.

  • The GJ translation scheme makes it possible to use existing Java library code as if it were generic. Since the Pizza translation scheme can affect method names, these tricks are impossible for Pizza.

  • The GJ design lifts some of the language restrictions in Pizza. It is now possible to cast to a parameterized type and to create a generic array, but both operations will generate unchecked warnings. See the documention for a detailed explanation.

  • The GJ compiler gjc is a closer match of the standard Java compiler javac than the Pizza compiler is. In particular, gjc can dynamically compile missing library files.

Comments and bug reports to the Pizza Group, pizza@cis.unisa.edu.au. Java is a trademark of Sun Microsystems. All software and documents on the Pizza site are © Copyright 1996, 1997 by the respective authors as attributed on each. Terms for redistribution are available.