public class Yikes1 {
public static void go(Long n) {
System.out.println(\"Long \"); // printed
}
public static void go(Short n) {
Syste
The binding sequence works as follows:
int--> int
)int --> long
)int --> Integer
)int --> int...
)Okay, when there's no method, which accepts short
, there's 2 options: autobox it into Short
or cast to integer. JLS states, that the second option in prefered:
Method invocation contexts allow the use of one of the following:
an identity conversion (§5.1.1)
a widening primitive conversion (§5.1.2)
a widening reference conversion (§5.1.5)
a boxing conversion (§5.1.7) optionally followed by widening reference conversion
an unboxing conversion (§5.1.8) optionally followed by a widening primitive conversion.
What you expect here is a boxing conversion
, but what you get is a widening primitive conversion
.
You can read more about boxing here to correctly understand the relation between short
and Short
.