This code compiles and runs in Java 6 (IBM Java 6) but does not compile in Java 8 (IBM Java 8, and Eclipse's built-in compiler) :
public class App {
public static void main(String[] args) {
App app = new App();
app.test(true, new Object());
}
void test(boolean b, Object... objects) {
}
void test(Object... objects) {
}
}
The compilation error is:
The method test(boolean, Object[]) is ambiguous for the type App
I found this problem while migrating a real application from Java 6 to Java 8. This code looks ok to me as varargs methods are usualy used as a last resort when Java chooses among overloaded methods.
What is the problem here?