Java Reference
In-Depth Information
Assignment from a raw type variable to a parameterized type
variablethe raw type variable might not refer to an instance of the
expected parameterized type.
Casts involving type variablesthe cast cannot be checked at
runtime because the erasure of the type variable is used.
Invocation of a method or constructor of a raw type if erasure
changes the type of a parameter.
Access to a field of a raw type if erasure changes the type of the
field.
The conversion between a raw type and a parameterized type adds an
additional conversion to those defined in Section 9.4 on page 216 : the
unchecked conversion. These unchecked conversions can be applied as
the final step in most of the conversion contextsfor example, as part of
an assignment. An unchecked conversion is always accompanied by an
"unchecked" warning, unless it has been suppressed by using the an-
notation SuppressWarnings("unchecked") if your compiler supports this.
Use of raw types can also lead to other complications. Consider a vari-
ation of the passThrough example from Chapter 11 repackaged as a gen-
eric interface:
interface PassThrough<T> {
T passThrough(T t);
}
Now consider an implementation of that interface:
class PassThroughString implements PassThrough<String> {
public String passThrough(String t) {
return t;
}
}
 
Search WWH ::




Custom Search