Java - No enclosing instance of type Foo is accessible

后端 未结 5 1253
再見小時候
再見小時候 2020-11-21 06:35

I have the following code:

class Hello {
    class Thing {
        public int size;

        Thing() {
            size = 0;
        }
    }

    public stat         


        
5条回答
  •  半阙折子戏
    2020-11-21 07:10

    Thing is an inner class with an automatic connection to an instance of Hello. You get a compile error because there is no instance of Hello for it to attach to. You can fix it most easily by changing it to a static nested class which has no connection:

    static class Thing
    

提交回复
热议问题