Is it really the case?
Consider the example: (part of my almost original code simplified and renamed)
package demo;
import static demo.WhatThe.f;
import java.util.RandomAccess;
public class Demo {
public void x() {
f();
}
}
class WhatThe implements RandomAccess {
public static WhatThe f() {
return null;
}
}
Do you think it compiles? If you say yes - you are almost right. It compiles well with Eclipse compiler, but every Sun Java compiler fails with the error like this:
demo\Demo.java:14: cannot find symbol
symbol: class RandomAccess
class WhatThe implements RandomAccess {
^
1 error
Why you'll ask: see this bug.
And now if you use Sun compiler, just change the order of imports (swap the first import with the second) and, behold, it works now:
package demo;
import java.util.RandomAccess;
import static demo.WhatThe.f;
public class Demo {
public void x() {
f();
}
}
class WhatThe implements RandomAccess {
public static WhatThe f() {
return null;
}
}
Anybody said the order does not matter?... :)
Today I've lost 2 hours hunting for this problem amongst hundreds of java files and 3rd party jars. If wish to spare you the same...
Regards,
Wojtek
Great catch! :-)
ReplyDelete