Java Reference
In-Depth Information
• If
T
is
byte
,
short
, or
int
, then use
new Integer(
x
)
.
• If
T
is
long
, then use
new Long(
x
)
.
• If
T
is
float
, then use
new Float(
x
)
.
• If
T
is
double
, then use
new Double(
x
)
.
This reference value is then converted to type
String
by string conversion.
Now only reference values need to be considered:
• If the reference is
null
, it is converted to the string “
null
” (four ASCII characters
n
,
u
,
l
,
l
).
• Otherwise, the conversion is performed as if by an invocation of the
toString
meth-
od of the referenced object with no arguments; but if the result of invoking the
toString
method is
null
, then the string “
null
” is used instead.
classes override it, notably
Boolean
,
Character
,
Integer
,
Long
,
Float
,
Double
, and
String
.
See §
5.4
for details of the string conversion context.
5.1.12. Forbidden Conversions
Any conversion that is not explicitly allowed is forbidden.
5.1.13. Value Set Conversion
Value set conversion
is the process of mapping a floating-point value from one value set to
another without changing its type.
an implementation of the Java programming language:
• If the value is an element of the float-extended-exponent value set, then the imple-
mentation may, at its option, map the value to the nearest element of the float value
set. This conversion may result in overflow (in which case the value is replaced by
an infinity of the same sign) or underflow (in which case the value may lose preci-
sion because it is replaced by a denormalized number or zero of the same sign).
• If the value is an element of the double-extended-exponent value set, then the im-
plementation may, at its option, map the value to the nearest element of the double
value set. This conversion may result in overflow (in which case the value is re-
placed by an infinity of the same sign) or underflow (in which case the value may