FULL PRODUCT VERSION :
"C:\Program Files\Java\jdk1.7.0_04\bin\javac" -version
javac 1.7.0_04-ea
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Compiler of jdk7_04_ea (and also jdk7_03) reports an error on overloaded methods with vararg Object...:
de\martini\App.java:18: error: reference to convertValue is ambiguous, both method convertValue(App.D,App.E,int,Object...) in App.B and method convert
Value(App.D,App.E,Object...) in App.B match
b.convertValue(d, e, -1, s);
REGRESSION. Last worked in version 6u29
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the source code provided below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect to get no compile error with Jdk7 compiler
(so the same which I get with JDK6 compiler). I was really surprised when I saw this error.
ACTUAL -
JDK7 compiler:
D:\Userdata\eclipse\ws3\java7test\src\main\java>"C:\Program Files\Java\jdk1.7.0_04\bin\javac" App.java
App.java:10: error: reference to convertValue is ambiguous, both method convertValue(App.D,App.E,int,Object...) in App.B and method convertValue(App.D
,App.E,Object...) in App.B match
b.convertValue(d, e, -1, s);
^
1 error
JDK6 compiler: No error
ERROR MESSAGES/STACK TRACES THAT OCCUR :
JDK7 compiler error message:
D:\Userdata\eclipse\ws3\java7test\src\main\java>"C:\Program Files\Java\jdk1.7.0_04\bin\javac" App.java
App.java:10: error: reference to convertValue is ambiguous, both method convertValue(App.D,App.E,int,Object...) in App.B and method convertValue(App.D
,App.E,Object...) in App.B match
b.convertValue(d, e, -1, s);
^
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class App {
public static void main(String[] args) {
System.out.println("Hello World!");
App x = new App();
B b = x.new B();
D d = x.new D();
E e = x.new E();
F f = x.new F();
String s = "Hallo";
b.convertValue(d, e, -1, s);
}
abstract class A {
abstract void convertValue(D d, E e, int i, Object... os);
abstract void convertValue(D d, F f, E e, int i, Object... os);
abstract void convertValue(D d, E e, Object... os);
}
class B extends A {
void convertValue(D d, E e, int i, Object... os) {
}
void convertValue(D d, E e, Object... os) {
}
void convertValue(D d, F f, E e, int i, Object... os) {
}
}
class C extends A {
void convertValue(D d, E e, int i, Object... os) {
}
void convertValue(D d, E e, Object... os) {
}
void convertValue(D d, F f, E e, int i, Object... os) {
}
}
class D {
public D() {
System.out.println("D - Constructor");
}
}
class E {
public E() {
System.out.println("E - Constructor");
}
}
class F {
public F() {
System.out.println("F - Constructor");
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Adapt the code ... but this is not what I expect from Java6 to Java7