I was just trying out few things using Varargs:
Just encountered with one problem:
class A {
public void func(int... a) {
System.out.println("int... a");
}
public void func(double... b) {
System.out.println("double... b");
}
}
public class B {
public static void main(String... args) {
A a = new A();
a.func(); //Getting no compilation error;instead func(int... a) is
//being called
}
}
where as if Class A is modified as :
class A {
public void func(int... a) {
System.out.println("int... a");
}
public void func(boolean... b) {
System.out.println("boolean... b");
}
}
Now i get the compile time error. Just wanted to know why was this not happening earlier when used with int and double. But now this is happening with only int and boolean. I understand ambiguity but this should happen in the first case also. I am using java 7. Its happening only in boolean's case. Would you please mind helping me providing the solution?
Thanks.