Adding Wildcards to the Java Programming Language

By: Mads Torgersen, Erik Ernst, Christian Plesner Hansen, Peter von der Ahe, Gilad Bracha, Neal Gafter

Abstract

This paper describes wildcards, a new language construct designed to increase the flexibility of object-oriented type systems with parameterized classes. Based on the notion of use-site variance, wildcards provide type safe abstraction over different instantiations of parameterized classes, by using ‘?’ to denote unspecified type arguments. Thus they essentially unify the distinct families of classes that parametric polymorphism introduces. Wildcards are implemented as part of the addition of generics to the JavaTM programming language, and is thus deployed world-wide as part of the reference implementation of the Java compiler javac available from Sun Microsystems, Inc. By providing a richer type system, wildcards allow for an improved type inference scheme for polymorphic method calls. Moreover, by means of a novel notion of wildcard capture, polymorphic methods can be used to give symbolic names to unspecified types, in a manner similar to the “open” construct known from existential types. Wildcards show up in numerous places in the Java Platform APIs of the newest release, and some of the examples in this paper are taken from these APIs.

Cite as:

Mads Torgersen, Erik Ernst, Christian Plesner Hansen, Peter von der Ahe, Gilad Bracha, Neal Gafter, “Adding Wildcards to the Java Programming Language”, Journal of Object Technology, Volume 3, no. 11 (December 2004), pp. 97-116, doi:10.5381/jot.2004.3.11.a5.

PDF | HTML | DOI | BiBTeX | Tweet this | Post to CiteULike | Share on LinkedIn

The JOT Journal   |   ISSN 1660-1769   |   DOI 10.5381/jot   |   AITO   |   Open Access   |    Contact