See the code below:
// 1st method
private static void method(Object o){
System.out.println("object method");
}
// 2nd method
private static void method(Object... o){
System.out.println("object vararg method");
}
public static void main(String [] ar){
method(null); // 1st call
Integer value=null;
method(value); // 2nd call
}
I expected 1st call and 2nd call both should invoke 1st method, thought null will prefer to match Object than Object... vararg. But I am wrong.
1st callinvoked2nd method2nd callinvoked1st method
My question is why or how null matches to Object... vararg and not Object in my code?