Mutability and Covariant Type Parameters in Object-Oriented Languages

Professor David Watt, University of Glasgow

The type parameter T of a generic class G is covariant if T1 is a subtype of T2 implies that G is a subtype of G. Covariance is of practical importance in object-oriented programming. Of all the numerous proposals to extend object-oriented languages with generic classes, NextGen is almost unique in that it permits some generic classes to have covariant type parameters, but with restrictions so stringent that few practical examples can be found. Monty, a new programming/scripting language, permits all immutable generic classes to have covariant type parameters, which is general enough to cover practical examples like collection classes. Strangely, however, neither NextGen nor Monty subsumes the other: each language permits some generic classes with covariant type parameters that the other language rejects. This talk compares and contrasts generic classes in Java 1.5, NextGen, and Monty, and proposes a generalization that subsumes all of them.