简体   繁体   中英

Is Eclipse Juno wrong with this ambiguous method error?

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?

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});

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM