Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 703
Roy van Rijn Avatar asked Jul 04 '12 06:07

Roy van Rijn


1 Answers

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

like image 108
Roy van Rijn Avatar answered Oct 26 '22 23:10

Roy van Rijn