Community
Participate
Working Groups
I20050215-2300 The compiler rejects autoboxing-calls to overloaded varargs methods as ambiguous. Class Works compiles fine with javac, whereas Eclipse thinks that all calls to take(..) are ambiguous. class Works { void take(char... chars) {} void take(Object... objs) {} void give() { take('a'); take('a', Character.valueOf('x')); take(Character.valueOf('x')); } } In class Ambiguous, both Eclipse and javac think they cannot solve the ambiguity: class Ambiguous { void take(char... chars) {} void take(Character... objs) {} void give() { take('a'); take('a', Character.valueOf('x')); take(Character.valueOf('x')); } }
*** Bug 87142 has been marked as a duplicate of this bug. ***
Here is another case: class X { void foo(int... i) {} void foo(Number... n) {} // void foo(Object... o) {} void test() { foo(1); foo(1, new Integer(1)); foo(new Integer(1)); } } All 3 message sends are ambiguous with javac as they are with Eclipse. Number is a superclass of Integer just as Object is. But when foo(Number...) is replaced with foo(Object...) it works.
Added AutoBoxing test101
Verified in 20050330-0500
In Eclipse 3.1, we are seeing this behavior again. The two method signatures: protected Object getResult( boolean isBlocking, Object... params ) {...} protected Object getResult( Object... params ) {...} With the following invocation: getResult( isBlocking ); is resulting (no pun intended) in the following error while building: "The method getResult(Object[]) is ambiguous for the type ..." Compiling code via the command line, works fine.