On Access Restriction with Java Wildcards

Java wildcards is a new programming mechanism shipped with the Java 5.0 release, introduced to provide a flexible subtyping mechanism for generic types. Safety is retained by providing rather peculiar and non-trivial mechanisms to restrict access to a class functionalities (methods and fields), which are currently not deeply described in the Java Language Specification. In this paper we develop on the theory of variant parametric types from which wildcards originated, and study a framework to describe these access restriction issues in detail, promoting the understanding and fruitful exploitation of this new programming concept. Our work is both technical and conceptual. On the one hand, we provide an abstract characterisation of formal rules to access restriction, then instantiated to the particular implementation of wildcards in current Java. On the other hand, we show that such a characterisation induces a natural description and understanding of access restriction in terms of the ability of (instances of) a generic class to produce/consume elements of the abstracted type.