The following code compiles fine in Java:
public static void main(String[] args) {
int i =5;
call(i);
}
static void call(int i){
System.out.println("int");
}
static void call(long i){
System.out.println("long");
}
static void call(Integer i){
System.out.println("Integer");
}
static void call(Object i){
System.out.println("Object");
}
But the following code gives compile time error:
public static void main(String[] args) {
int i =5;
call(i);
}
static void call(int... i){
System.out.println("int...");
}
static void call(long... i){
System.out.println("long...");
}
static void call(Integer... i){
System.out.println("Integer...");
}
static void call(Object... i){
System.out.println("Object...");
}
Why the similar call mechanism is not maintained by Java while working with var-args? In the second example also, the call should go to method static void call(int... i)