Datasheet
The need to create an Integer object to place an int into the collection is no longer needed. The boxing
conversion happens such that the resulting reference type’s
value() method (such as intValue() for
Integer) equals the original primitive type’s value. Consult the following table for all valid boxing con-
versions. If there is any other type, the boxing conversion becomes an identity conversion (converting
the type to its own type). Note that due to the introduction of boxing conversions, several forbidden con-
versions referring to primitive types are no longer forbidden because they now can be converted to cer-
tain reference types.
Primitive Type Reference Type
boolean Boolean
byte Byte
char Character
short Short
int Integer
long Long
float Float
double Double
Unboxing Conversions
Java also introduces unboxing conversions, which convert a reference type (such as Integer or Float)
to its primitive type (such as
int or float). Consult the following table for a list of all valid unboxing
conversions. The conversion happens such that the
value method of the reference type equals the
resulting primitive value.
Reference Type Primitive Type
Boolean boolean
Byte byte
Character char
Short short
Integer int
Long long
Float float
Double double
20
Part I: Thinking Like a Java Developer
05_777106 ch01.qxp 11/28/06 10:43 PM Page 20