No enclosing instance of type is accessible解决方法

出现No enclosing instance of type is accessible解决方法

# No enclosing instance of type is accessible解决方法
No enclosing instance of type SxtStu is accessible. Must qualify the allocation with an enclosing instance of type SxtStu (e.g. x.new A() where x is an instance of SxtStu).

根据提示,没有可以访问的实例 SxtStu,必须分配一个合适的外部类实例以访问内部类。
正确的方式可以是:
# No enclosing instance of type is accessible解决方法

或者第二种# No enclosing instance of type is accessible解决方法
解决办法# No enclosing instance of type is accessible解决方法

关于内部类

依然是一个独立的类,在编译之后会内部类会被编译成独立的.class文件,但是前面冠以外部类的类命和$符号。
内部类不能用普通的方式访问。内部类是外部类的一个成员,因此内部类可以自由地访问外部类的成员变量,无论是否是private的。
成员内部类内不允许有任何静态声明!
能够访问成员内部类的唯一途径就是通过外部类的对象!

相关文章: