Java Reference
In-Depth Information
class Outer<T>{
class Inner<S> {
S s;
}
}
It is not possible to access Inner as a partially raw type (a “rare” type):
Click here to view code image
Outer.Inner<Double> x = null; // illegal
Double d = x.s;
because Outer itself is raw, hence so are all its inner classes including Inner , and so it is
not possible to pass any type arguments to Inner.
The superclasses (respectively, superinterfaces) of a raw type are the erasures of the super-
classes (superinterfaces) of any of its parameterized invocations.
The type of a constructor (§ 8.8 ), instance method (§ 8.4 , § 9.4 ), or non-static field (§ 8.3 ) M
of a raw type C that is not inherited from its superclasses or superinterfaces is the raw type
that corresponds to the erasure of its type in the generic declaration corresponding to C .
The type of a static method or static field of a raw type C is the same as its type in the gen-
eric declaration corresponding to C .
It is a compile-time error to pass type arguments to a non- static type member of a raw type
that is not inherited from its superclasses or superinterfaces.
It is a compile-time error to attempt to use a type member of a parameterized type as a raw
type.
This means that the ban on “rare” types extends to the case where the qualifying type
is parameterized, but we attempt to use the inner class as a raw type:
Outer<Integer>.Inner x = null; // illegal
This is the opposite of the case discussed above. There is no practical justification for
this half-baked type. In legacy code, no type arguments are used. In non-legacy code,
we should use the generic types correctly and pass all the required type arguments.
The supertype of a class may be a raw type. Member accesses for the class are treated as
normal, and member accesses for the supertype are treated as for raw types. In the con-
structor of the class, calls to super are treated as method calls on a raw type.
Search WWH ::




Custom Search