Java Reference
In-Depth Information
• Widening reference conversions
• Narrowing reference conversions
• Boxing conversions
• Unboxing conversions
• Unchecked conversions
• Capture conversions
• String conversions
• Value set conversions
There are five
conversion contexts
in which conversion of expressions may occur. Each
context allows conversions in some of the categories named above but not others. The term
“conversion” is also used to describe the process of choosing a specific conversion for such
a context. For example, we say that an expression that is an actual argument in a method in-
vocation is subject to “method invocation conversion,” meaning that a specific conversion
will be implicitly chosen for that expression according to the rules for the method invoca-
tion argument context.
One conversion context is the operand of a numeric operator such as
+
or
*
. The conversion
process for such operands is called
numeric promotion
. Promotion is special in that, in the
case of binary operators, the conversion chosen for one operand may depend in part on the
type of the other operand expression.
the five conversion contexts are described:
type of a specified variable.
Assignment conversion may cause an
OutOfMemoryError
(as a result of boxing con-
be thrown at run time.
a method or constructor invocation and, except in one case, performs the same
conversions that assignment conversion does.
Method invocation conversion may cause an
OutOfMemoryError
(as a result of box-