简体   繁体   中英

“java.lang.NoSuchFieldError: super” exception - bug in compiler?

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.

最后,这个问题被Java开发人员支持团队认为是一个错误,这里有一个链接: https//bugs.java.com/bugdatabase/view_bug.do?video_id = JDK- 8194847

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM