Java Reference
In-Depth Information
generic type system seeks to support migration compatibility. Migration compatibiliy
allows the evolution of existing code to take advantage of generics without imposing
dependencies between independently developed software modules.
The price of migration compatibility is that a full and sound reification of the generic
type system is not possible, at least while the migration is taking place.
4.8. Raw Types
To facilitate interfacing with non-generic legacy code, it is possible to use as a type the
erasure (§ 4.6 ) of a parameterized type (§ 4.5 ) or the erasure of an array type (§ 10.1 ) whose
element type is a parameterized type. Such a type is called a raw type .
More precisely, a raw type is defined to be one of:
• The reference type that is formed by taking the name of a generic type declaration
without an accompanying type argument list.
• An array type whose element type is a raw type.
• A non-static member type of a raw type R that is not inherited from a superclass or
superinterface of R .
A non-generic class or interface type is not a raw type.
To see why a non- static type member of a raw type is considered raw, consider the fol-
lowing example:
Click here to view code image
class Outer<T>{
T t;
class Inner {
T setOuterT(T t1) { t = t1; return t; }
}
}
The type of the member(s) of Inner depends on the type parameter of Outer . If Outer is
raw, Inner must be treated as raw as well, as there is no valid binding for T .
This rule applies only to type members that are not inherited. Inherited type members
that depend on type variables will be inherited as raw types as a consequence of the
rule that the supertypes of a raw type are erased, described later in this section.
Another implication of the rules above is that a generic inner class of a raw type can
itself only be used as a raw type:
Search WWH ::




Custom Search