Community
Participate
Working Groups
The following snippet fails to compile with HEAD. (build I20110514-0800). package snippet; class Test { public static void foo(int ...i) {} public static void foo(double...d) {} public static void main(String[] args) { foo(1, 2, 3); // foo flagged ambiguous } } Eclipse behaviour is consistent with javac 5,6 but with javac7 this has been fixed. See javac bug http://bugs.sun.com/view_bug.do?bug_id=6199075 for detailed explanation. This needs to be fixed for eclipse compiler as well.
I would target 3.7.1 to match the Java 7 behavior when the Java 7 support is released.
Don't expect to get to this before 3.8. Retargetting.
While working on this I ran into this case in org.eclipse.jdt.core.tests.compiler.regression.VarargsTest.test015() where we have codified the wrong behavior as the expected behavior. The test case being: public class X { public static void main(String[] s) { Y.count(new int[0]);// for some reason this is not ambiguous } } class Y { public static void count(int[] array, int ... values) { System.out.print(1); } public static void count(int[] array, int[] ... values) { System.out.print(2); } } In fact both javac5 and javac6 match eclipse behavior i.e they don't flag the call as ambiguous. Javac7 does report the call as being ambiguous. Javac7's behavior is the right one as shown by the following slightly modified test case: public class X { public static void main(String[] s) { Y.count(new int[0]);// for some reason this is not ambiguous Y.count(new int[0], 10); // binds only to 1st count Y.count(new int[0], new int[0][0]); // binds only to 2nd count } } class Y { public static void count(int[] array, int ... values) { System.out.print(1); } public static void count(int[] array, int[] ... values) { System.out.print(2); } } This test case proves that neither is more specific than the other and so the call is ambiguous.
Combined fix and tests for bug 346039 and bug 346038 have been released into 3.8 stream via 85f48e0f08275e1f81e9995073d5c4f69bfd0707. Some existing tests had to be remastered - in all instances the behavior matches JDK 7b147 behavior.
Verified for 3.8M4 with build I20111204-2000.
*** Bug 379871 has been marked as a duplicate of this bug. ***
*** Bug 383780 has been marked as a duplicate of this bug. ***