`

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

    博客分类:
  • java
阅读更多

转载:http://blog.csdn.net/thirtydevs/article/details/21661485

---------------------------------------------------------------------------------------

 

[java] view plain copy在CODE上查看代码片派生到我的代码片
  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在CODE上查看代码片派生到我的代码片
  1. A a = new A();  
  2. A.B ab = a.new B();  


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

分享到:
评论

相关推荐

    Android Studio无法执行Java类的main方法问题及解决方法

    Android Studio升级到哦最新版3.6.1后,新建了个项目,发现无法执行Java类的main方法。试了网上的各种方法,比如切换gradle离线模式、gradle.properties中添加android.enableAapt2=false等,我还尝试了重新情况...

    java-嵌套类(inner class)-来自oracle官网

    1.Nested Class(嵌套类) 1.1.Nested class 1.2.Nested class的分类 1.3.Nested class的使用原因 2.Static Nested Classes 2.1.static nested class访问enclosing class(outer class)的成员 2.2.enclosing...

    Android 中LayoutInflater.inflate()方法的介绍

    主要介绍了Android 中LayoutInflater.inflate()方法的介绍的相关资料,希望通过本文大家能掌握这部分内容,需要的朋友可以参考下

    java开发中嵌套类的详解及实例

    主要介绍了 java开发中嵌套类的详解及实例的相关资料,一般把定义内部类的外围类成为包装类(enclosing class)或者外部类,需要的朋友可以参考下

    2009 达内Unix学习笔记

    mkdir 创建目录(必须有创建目录的权限) 用法 mkdir [-m 模式] [-p] dirname ... mkdir dir1/dir2 在dir1下建dir2 mkdir dir13 dir4 dir5 连建多个 mkdir ~/games 用户主目录下建(默认在当前目录下创建) mkdir -...

    Java解决No enclosing instance of type PrintListFromTailToHead is accessible问题的两种方案

    主要介绍了Java解决No enclosing instance of type PrintListFromTailToHead is accessible问题的两种方案的相关资料,需要的朋友可以参考下

    Google C++ Style Guide(Google C++编程规范)高清PDF

    For example, if your header file uses the File class in ways that do not require access to the declaration of the File class, your header file can just forward declare class File; instead of having ...

    Eclipse快捷键大全(

    编辑 Select Enclosing Element Alt+Shift+向上键 Editing in Structured Text Editors 编辑 选择外层元素 Alt+Shift+向上键 编辑 Java 源代码 编辑 Restore Last Selection Alt+Shift+向下键 Editing in Structured...

    eclipse java注释模板

    </template><template autoinsert="true" context="filecomment_context" deleted="false" description="已创建的 Java 文件的注释" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name=...

    外文翻译1

    thus an intractable preprocessing of enclosing blob gaps is necessary. Loy and B

    在线图片编辑 图片可拖动 裁剪区固定中间

    在线图片编辑 图片可拖动 裁剪区固定中间 有预览区 项目中应用

    embedded system design

    This importance of embedded systems is so far not well reflected inmany of the current curricula. This book is intended as an aid for changing this situation. It provides the material for a first ...

    Fractions to Decimals

    Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal representation has a repeating ...

    JS 有名函数表达式全面解析

    Example #1: Function ... // “function” Remember how I mentioned that an identifier of named function expression is not available in an enclosing scope? Well, JScript doesn’t agree with specs on thi

    max200技术手册

    数控等离子切割技术资料The user is responsible for installing and using the plasma equipment according to the manufacturer’s instructions. If electromagnetic disturbances are detected then it shall be...

    demon_registration.zip_3d_Demons_REGISTRATION_demon_image regist

    Image registration procedures, Multimodality non-rigid registration, the effect is obvious, enclosing the test sample

    Borland Delphi 2005 Architect Update 3

    project loading is very SLOW4.00 of 5 Closed10314 Error Insight fails to flag an error4.00 of 5 Closed10248 Alignment Palette in VCL form designer malfunctions5.00 of 5 Closed10190 List view selected ...

    Using LUA with Visual C++ (Introduction)

    Don't forget that this document is only a quick introduction and that it is not a complete tutorial about LUA. How to embed LAU into C++? Another way to formulate this question : "How can I use ...

    enclosing.zip_区域覆盖_圆与蜂窝_基站选择_小圆覆盖大圆_蜂窝最大覆盖

    本程序主要用于求解小圆覆盖大圆问题,本文求解过程中优先选择蜂窝状正六边形网格法求解。若正六边形网格不能恰好完整覆盖目标,此时,需要先采用圆周覆盖法将大圆圆周完整覆盖,再对大圆中心区域填补的方法,填补时...

    Eclipse新建项目不可选择Java Project问题解决方案

    主要介绍了Eclipse新建项目不可选择Java Project问题解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

Global site tag (gtag.js) - Google Analytics