The following code written in Java-9 being run gives me a very weird and funny exception in runtime:
Exception in thread "main" java.lang.NoSuchFieldError: super
at A$C.test(A.java:15)
at A.main(A.java:5)
The code:
public class A {
public static void main(String[] args) {
new C().test();
}
interface B {
private void test() {
}
}
static class C implements B {
void test() {
B.super.test();
}
}
}
I am wondering: is it designed so, or ideally this code shouldn't be compiled, and therefore this is a compiler bug? (I personally believe that this is a bug).
UPD: Submitted a bug, ID : 9052188
UPD-2: It looks like B.super.test()
is generally a valid construction, because if test()
method is default
than it works fine. This fact just makes things more complicated.