The following snippet (abstracted from real-world code) compiles and runs in Eclipse.
package1/Outer.java:
package package1;
import package1.Outer.Mid.Inner;
import package2.Bar;
public class Outer {
final Mid mid = new Mid();
public Outer() {
mid.setInner(new Inner() {
@Override public void foo() {
System.out.println("In Outer.foo()");
}
});
}
public static class Mid implements Bar {
private Inner inner;
public void setInner(Inner inner) {
this.inner = inner;
}
public Inner getInner() {
return this.inner;
}
@Override
public void bar() {}
interface Inner {
void foo();
}
}
}
package2/Bar.java:
package package2;
public interface Bar {
void bar();
}
However, it fails with this error when compiling using javac:
package1\Outer.java:31: cannot find symbol
symbol : class Bar
location: class package1.Outer
public static class Mid implements Bar {
^
package1\Outer.java:42: method does not override or implement a method from a supertype
@Override
^
2 errors
Now, if I switch the order of the import statements, like so:
import package2.Bar;
import package1.Outer.Mid.Inner;
...then it compiles in both Eclipse and javac. Clearly the order of the import statements seems to matter...but why?
Notes:
package1.Outer.Mid.Inner
import is even necessary, given the Inner
interface is nested within Outer.java, but both Eclipse and javac seem to require itThis looks like a bug, as reported on Oracle's bug database here.
According to the JLS §7.5, the order of import
-statements should not matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With