as i wrote in my question that when the method callMethod() is invoked by passing an integer argument--- that means object.callMethod(4); i am writting the whole code for better understanding.
class anything{
public static void main (
String args[]){
Rameshwar object=new Rameshwar();
// invoking the methd by passing 4 as argument
object.callMethod(4); //
}
}
class Rameshwar {
// condition A)
public static void callMethod(Integer i){ // 1.
System.out.println("Wrapper");
}
public static void callMethod(int i){ // 2.
System.out.println("Primitive");
}
// both the above methods are Overloaded methods. when we pass 4 as argument to the method then 2. method is invoked b\c priority has is given to int(premitive) over
Integer(wrapper) that is ok. now i want to know that why this priority rule is not applied for following condition ...... B)
// -----------------------------------------------------------------------------------------------------------
//condition B)
public static void callMethod(Integer... i){
System.out.println("Wrapper");
}
public static void callMethod(int... i){
System.out.println("Primitive");
}
}
in the above condition B) there are two Overloaded methods with parameter as variable arguments. in this case also i am passing 4 as parameter (we can pass more than arguments also as it is var args but i am passing here 4 only), then compiler show error that
-------------- > reference to both the methods is ambigous
i want to know that why it is giving error ?
since both methods contains var args (i.e common on both) then why here the methods are not invoked on the basis of priority(giving more priority to int... than Integer...)