in the example below
public static void foo(Integer i) {
System.out.println("foo(Integer)");
}
public static void foo(short i) {
System.out.println("foo(short)");
}
public static void foo(long i) {
System.out.println("foo(long)");
}
public static void foo(int... i) {
System.out.println("foo(int ...)");
}
public static void main(String[] args) {
foo(10);
}
foo calls the long signed method, because the JVM resolves that the closest type of int is long, which is understandable.
It prefers to do this by invoking the Integer or int (Integer) signature method, which would be perfectly compatible.
What is the reason, in terms of language design, for "long" to be more appropriate than Integer or int ...? Is it expensive for the JVM to do this type of casting internally? (either for int [] or Integer)