创建java类中类出现is not an enclosing class

Posted 那些年的代码

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建java类中类出现is not an enclosing class相关的知识,希望对你有一定的参考价值。

 技术图片技术图片
  1. public class A {  
  2.     public class B {  
  3.           
  4.     }  
  5. };  

需要实例B类时,按照正逻辑是,A.B ab = new A.B();

那么编译器就会出现一个错误--"is not an enclosing class"

再翻看相关的Java代码,发现原来写法出错了!正确的做法是

[java] view plain copy 技术图片技术图片
  1. A a = new A();  
  2. A.B ab = a.new B();  


没有静态(static)的类中类不能使用外部类进行.操作,必须用实例来进行实例化类中类.

以上是关于创建java类中类出现is not an enclosing class的主要内容,如果未能解决你的问题,请参考以下文章

[Java A] – is not an enclosing class

Java中报错No enclosing instance of type caiquan is accessible. Must qualify the allocation with an encl

Android Studio解决unspecified on project app resolves to an APK archive which is not supported

Android Studio解决unspecified on project app resolves to an APK archive which is not supported

(转)Android Studio解决unspecified on project app resolves to an APK archive which is not supported(示例代码

ERROR in AppModule is not an NgModule