Java Reference
In-Depth Information
Iterator<String> iterator()
from the Collection<String> superinterface. However, the type RawMembers inherits iterat-
or() from the erasure of Collection<String> , which means that the return type of iterator()
is the erasure of Iterator<String> , Iterator .
As a result, the attempt to assign to rw.iterator() requires an unchecked conversion
5.1.9 ) from Iterator to Iterator<String> , causing an unchecked warning to be issued.
In contrast, the static member cng retains its full parameterized type even when ac-
cessed through a object of raw type. (Note that access to a static member through an
instance is considered bad style and is to be discouraged.) The member myNumbers is
inherited from the NonGeneric class (whose erasure is also NonGeneric ) and so retains its
full parameterized type.
Raw types are closely related to wildcards. Both are based on existential types. Raw
types can be thought of as wildcards whose type rules are deliberately unsound, to ac-
commodate interaction with legacy code. Historically, raw types preceded wildcards;
they were first introduced in GJ, and described in the paper Making the future safe
for the past: Adding Genericity to the Java Programming Language by Gilad Bracha,
Martin Odersky, David Stoutamire, and Philip Wadler, in Proceedings of the ACM
Conference on Object-Oriented Programming, Systems, Languages and Applications
(OOPSLA 98) , October 1998.
4.9. Intersection Types
An intersection type takes the form T 1 & ... & T n ( n > 0), where T i (1 ≤ i n ) are type ex-
pressions.
Intersection types arise in the processes of capture conversion (§ 5.1.10 ) and type inference
15.12.2.7 ) . It is not possible to write an intersection type directly as part of a program; no
syntax supports this.
The values of an intersection type are those objects that are values of all of the types T i for
1 ≤ i n .
The members of an intersection type T 1 & ... & T n are determined as follows:
• For each T i (1 ≤ i n ), let C i be the most specific class or array type such that T i <:
C i . Then there must be some T k <: C k such that C k <: C i for any i (1 ≤ i n ), or a
compile-time error occurs.
Search WWH ::




Custom Search