Java Reference
In-Depth Information
• If an argument value of type
double
is an element of the double-extended-exponent
value set, then the implementation must map the value to the nearest element of
the double value set. This conversion may result in overflow or underflow.
The only exceptions that an method invocation conversion may cause are:
• A
ClassCastException
if, after the type conversions above have been applied, the res-
ulting value is an object which is not an instance of a subclass or subinterface of
• An
OutOfMemoryError
as a result of a boxing conversion.
• A
NullPointerException
as a result of an unboxing conversion on a null reference.
Method invocation conversions specifically do not include the implicit nar-
rowing of integer constants which is part of assignment conversion (§
5.2
). The
designers of the Java programming language felt that including these impli-
cit narrowing conversions would add additional complexity to the overloaded
method matching resolution process (§
15.12.2
).
Thus, the program:
class Test {
static int m(byte a, int b) { return a+b; }
static int m(short a, short b) { return a-b; }
public static void main(String[] args) {
System.out.println(m(12, 2)); // compile-time error
}
}
causes a compile-time error because the integer literals
12
and
2
have type
int
, so
plicit narrowing of integer constants would need additional rules to resolve cases like
this example.
5.4. String Conversion
String conversion applies only to an operand of the binary
+
operator which is not a
String
when the other operand is a
String
.