Java Reference
In-Depth Information
• From type
long
to type
Long
• From type
float
to type
Float
• From type
double
to type
Double
• From the null type to the null type
This rule is necessary because the conditional operator (§
15.25
) applies boxing
conversion to the types of its operands, and uses the result in further calcula-
tions.
At run time, boxing conversion proceeds as follows:
• If
p
is a value of type
boolean
, then boxing conversion converts
p
into a reference
r
of class and type
Boolean
, such that
r
.booleanValue() ==
p
• If
p
is a value of type
byte
, then boxing conversion converts
p
into a reference
r
of
class and type
Byte
, such that
r
.byteValue() ==
p
• If
p
is a value of type
char
, then boxing conversion converts
p
into a reference
r
of
class and type
Character
, such that
r
.charValue() ==
p
• If
p
is a value of type
short
, then boxing conversion converts
p
into a reference
r
of
class and type
Short
, such that
r
.shortValue() ==
p
• If
p
is a value of type
int
, then boxing conversion converts
p
into a reference
r
of
class and type
Integer
, such that
r
.intValue() ==
p
• If
p
is a value of type
long
, then boxing conversion converts
p
into a reference
r
of
class and type
Long
, such that
r
.longValue() ==
p
• If
p
is a value of type
float
then:
♦ If
p
is not NaN, then boxing conversion converts
p
into a reference
r
of class
and type
Float
, such that
r
.floatValue()
evaluates to
p
♦ Otherwise, boxing conversion converts
p
into a reference
r
of class and type
Float
such that
r
.isNaN()
evaluates to
true
• If
p
is a value of type
double
, then:
♦ If
p
is not NaN, boxing conversion converts
p
into a reference
r
of class and
type
Double
, such that
r
.doubleValue()
evaluates to
p
♦ Otherwise, boxing conversion converts
p
into a reference
r
of class and type
Double
such that
r
.isNaN()
evaluates to
true
• If
p
is a value of any other type, boxing conversion is equivalent to an identity con-