If I declare just the 2 varargs methods as follows:
public void foo(String... strings) {
System.out.println("Foo with Strings");
}
and
public void foo(int... ints) {
System.out.println("Foo with ints");
}
and then have the code:
foo();
this is a compiler error due to the ambiguity as expected.
However if I have just the following 2 versions of foo:
public void foo(Object... objects) {
System.out.println("Foo with Objects");
}
and
public void foo(int... ints) {
System.out.println("Foo with ints");
}
then the code
foo();
calls the ints version of the method. Can anyone explain why the second example isn't similarly ambiguous and why it resolves to the int method over the Object method. Thanks.