Adding Wildcards to the Java Programming Language

ADVERTISEMENT


of that language [18]. The decision to include parametric polymorphism – also known as genericity or generics – in the Java programming language was …

ABSTRACT

This paper describes wildcards, a new language construct designed to increase the ?exibility of object-oriented type systems with parameterized classes. Based on the notion of use-site variance, wildcards provide a type safe abstraction over di?erent instantiations of parameterized classes, by using ‘?’ to denote unspeci?ed type arguments. Thus they essentially unify the distinct families of classes often introduced by parametric polymorphism. Wildcards are implemented as part of the upcoming addition of generics to the JavaTM programming language, and will thus be 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 unspeci?ed 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 upcoming release, and some of the examples in this paper are taken from these APIs.

Categories and Subject Descriptors

D.3.3 [Language Constructs and Features]: Classes and objects, Data types and structures, Polymorphism

Keywords

Wildcards, genericity, parameterized types

1. INTRODUCTION

Parametric polymorphism is well-known from functional languages such as Standard ML [22], and over the past two decades similar features have been added to a number of object-oriented languages [21, 28, 13].

For some time it has been clear that the Java programming language was going to be extended with parametric polymorphism in the form of parameterized classes and polymorphic methods, i.e., classes and methods with type parameters. A similar mechanism has recently been described for C# [10], and is likely to become part of a future version of that language [18].

The decision to include parametric polymorphism – also known as genericity or generics – in the Java programming language was preceded by a long academic debate. Several proposals such as GJ and others [25, 1, 24, 4, 7] were presented, thus advancing the ?eld of programming language research. It became increasingly clear that the mechanism on its own, imported as it were from a functional context, lacked some of the ?exibility associated with object-oriented subtype polymorphism.

Download
Adding Wildcards to the Java Programming Language.pdf

Leave a Reply


Map: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67