Java Reference
In-Depth Information
• If r is a reference of type Byte , then unboxing conversion converts r into
r .byteValue()
• If r is a reference of type Character , then unboxing conversion converts r into
r .charValue()
• If r is a reference of type Short , then unboxing conversion converts r into
r .shortValue()
• If r is a reference of type Integer , then unboxing conversion converts r into r .in-
tValue()
• If r is a reference of type Long , then unboxing conversion converts r into
r .longValue()
• If r is a reference of type Float , unboxing conversion converts r into r .floatValue()
• If r is a reference of type Double , then unboxing conversion converts r into
r .doubleValue()
• If r is null , unboxing conversion throws a NullPointerException
A type is said to be convertible to a numeric type if it is a numeric type (§ 4.2 ) , or it is a
reference type that may be converted to a numeric type by unboxing conversion.
A type is said to be convertible to an integral type if it is an integral type, or it is a reference
type that may be converted to an integral type by unboxing conversion.
5.1.9. Unchecked Conversion
Let G name a generic type declaration with n type parameters.
There is an unchecked conversion from the raw class or interface type (§ 4.8 ) G to any para-
meterized type of the form G < T 1 ,..., T n > .
There is an unchecked conversion from the raw array type G [] to any array type type of the
form G < T 1 ,..., T n >[] .
Use of an unchecked conversion causes a compile-time unchecked warning unless G < ... > is
a parameterized type in which all type arguments are unbounded wildcards (§ 4.5.1 ) , or the
unchecked warning is suppressed by the SuppressWarnings annotation (§ 9.6.3.5 ).
Unchecked conversion is used to enable a smooth interoperation of legacy code, writ-
ten before the introduction of generic types, with libraries that have undergone a con-
version to use genericity (a process we call generification). In such circumstances
(most notably, clients of the Collections Framework in java.util ), legacy code uses raw
types (e.g. Collection instead of Collection<String> ). Expressions of raw types are passed
Search WWH ::




Custom Search