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
the erasure (§ 4.6 ) of the corresponding formal parameter type.
This circumstance can only arise as a result of heap pollution (§ 4.12.2 ) .
• 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:
Click here to view code image
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
neither method m matches under the rules of (§ 15.12.2 ). A language that included im-
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 .
In this single special case, the non- String operand to the + is converted to a String 5.1.11 )
and evaluation of the + operator proceeds as specified in § 15.18.1 .
Search WWH ::




Custom Search