Java出现No enclosing instance of type H is accessible. Must qualify the allocation with an enclosing

来源:互联网 发布:杭州网站建设宣盟网络 编辑:程序博客网 时间:2024/05/22 11:38

就是main函数中调用内部静态类,我把内部静态类改成非静态报的错。

类大概是

class A

{

        public static void main(String[] args) {

B  b= new  B();  //这里报错

//应该写成: A.B b = new A().new B();

//原因是 静态函数加载的早,A,B都是非静态类,不明确A就不知道B。当然你把B写成静态类也能不报错,但B需要那么优先放入内存么?

}

class B

{

}

}



    

0 0
原创粉丝点击