外部类的静态成员不允许直接使用非静态内部类

报错:No enclosing instance of type test is accessible. Must qualify the allocation with an enclosing instance of type test (e.g. x.new A() where x is an instance of test).不能访问类型test的封闭实例。 必须使用类型为test的封闭实例限定分配(例如x.new A(),其中x是test的实例)。

原因分析:非静态内部类的实例是寄生在外部类的实例中的,要访问非静态内部类,前提是外部类的实例已经存在。故创建了外部类的实例后,就可以顺利使用非静态内部类了。

猜你喜欢

转载自blog.csdn.net/m0_37974032/article/details/81165897
今日推荐