The answer to this lies in the following taken from the
Java Language Specification, 3rd Edition:
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 implicit nar-
rowing conversions would add additional complexity to the overloaded method
matching resolution process (�15.12.2).
Thus, the example:
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
implicit narrowing of integer constants would need additional rules to resolve
cases like this example.
So even something as simple as new Byte(1) is not allowed because the formal parameter of the Byte constructor is a
byte not an
int.
[ February 05, 2007: Message edited by: Barry Gaunt ]