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.
In the end this issue was admitted as a bug by the Java Developer Support team, here is a link: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8194847
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