Question

Today I've been playing around with Eclipse Juno. Coming from Helios it is a great upgrade. Everything is working fine, except one new compile error.

We are using the java.net framework 'Fuse' and we call the following method:

ResourceInjector.get().inject(true, this);

Eclipse tells us:

The method inject(Object[]) is ambiguous for the type ResourceInjector

The following methods collide:

inject(Object... components);
inject(boolean arg0, Object... arg1);

It worked fine (with Java 1.6.0.25) in Eclipse Helios, but now it gives a compile error and doesn't want to run anymore. It seems to us that this is a bug in Eclipse Juno, if we build using Maven is builds fine... Does anybody know a work-around for this?

Was it helpful?

Solution

This is actually a bug in Java 5 and Java 6. This has been fixed in Java 7, and Eclipse now checks for this 'bug'.

More about the bug here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6886431

What method should be called in the following case?

inject(true);

Both can apply, sure, but the primitive boolean surely is a better match? Not according to the Java Language Specification (JLS):

  • Per 15.12.2.5, neither is more specific than the other (int <: Object is not true)

A work-around (we aren't able to change Fuse itself):

ResourceInjector.get().inject(true, new Object[] {this});

OTHER TIPS

Related question here: "method is ambiguous for the type" but the types are NOT ambiguous (and the error comes by upgrade from eclipse 3.7.2 to eclipse 4.2), copying my answer:

A bug has been filed and fixed for this problem bug 383780.
Here is the documentation of the fix: https://bugs.eclipse.org/bugs/attachment.cgi?id=218320

Basically, to fix the compiler error, get the latest eclipse Juno release build(4.2.1 as of now), add the following line after -vmargs in eclipse.ini: (then you might need to restart eclipse and rebuild you projects)

-DtolerateIllegalAmbiguousVarargsInvocation=true

it is really weird that, if you change the API

inject(boolean arg0, Object... arg1);

to

inject(Boolean arg0, Object... arg1);

then inject(true, this) not ambiguous any more

I thinks the bug fix http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6199075 is definitely a BAD idea

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top