DRY-216: Deal with cyclic static imports
Cyclic static imports are very obscure. They don’t seem to be forbidden by the JLS, and javac shows weird behaviour on some horrible test cases. Figure out what to do.
package p;
import static q.Fred.*;
public class Bar {
public static class A extends C {}
}
—————————————
package q;import static p.Bar.*;
public class Fred {
public static class B extends A {}
public static class C {}
}
—————————————
martin@linux:~/tmp/test/static-import> javac p/.java q/.java
p/Bar.java:6: cannot find symbol
symbol : class C
location: class p.Bar
public static class A extends C {}
^
1 error
—————————————There are no cyclic inheritance relations here, but obviously the cyclic imports make it difficult for the type-checker to decide what to do first. In this case, the error is gone if you remove the static import and the class declaration of B, which is rather interesting.
I don’t think that the JLS forbids this for static member classes, since the code compiles if you use fully qualify names.
So, this might be a bug in javac, or the JLS should say something about cyclic static imports.
Submitted on 19 February 2006 at 03:44
Log in to post comments