I was trying to figure out the ins-and-outs of varargs and wrote the following code
public class VarArgTest {
/**
* @param args
*/
public static void main(String[] args) {
VarArgTest v = new VarArgTest();
//Code 1
System.out.println("haha");
}
public void m1(Integer a, Integer... ints) {
System.out.println("1");
}
public void m1(Integer... ints) {
System.out.println("2");
}
}
Now if I replace Code 1 by
v.m1(new Integer(1), new Integer(2));
I get the following message
The method m1(Integer, Integer[]) is ambiguous for the type VarArgTest
My question is, why throw the error at client code? Should it not be caught by compiler while defining the two m1 methods?