java内部类编译错误 No enclosing instance of type Test03 is accessible. Must qualify the allocation with 。。。
来源:互联网 发布:如何用u盘重装mac 编辑:程序博客网 时间:2024/05/16 03:24
首先看一段代码
public class Test03 { class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } } public static void main(String[] args) { ListNode head=new ListNode(1); }}
上述Test03的main函数是static,new了一个ListNode对象,就会编译错误,No enclosing instance of type Test03 is accessible. Must qualify the allocation with an enclosing instance of type Test03 (e.g. x.new A() where x is an instance of Test03).
可以这样理解,内部类相当于类的一个成员,在类的静态函数中是无法访问非静态成员的,所以会有上述编译错误,建议以后这种编程题,把ListNode类写在Test03外边(推荐),而不是内部类的形式。或者把ListNode声明为static的。
阅读全文
0 0
- java内部类编译错误 No enclosing instance of type Test03 is accessible. Must qualify the allocation with 。。。
- 使用内部类时提示No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosi
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosi
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleT
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java错误No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- <java>No enclosing instance of type GraphicFrame is accessible. Must qualify the allocation with an
- JAVA异常处理 No enclosing instance of type a12_1 is accessible. Must qualify the allocation with
- Java出现No enclosing instance of type ImageViewer is accessible. Must qualify the allocation with an
- Java编译时出现 No enclosing instance of type Main is accessible. Must qualify the allocation with an encl
- java编译报错No enclosing instance of type initial is accessible. Must qualify the allocation with an enc
- Java编译时出现 No enclosing instance of type Main is accessible. Must qualify the allocation with an encl
- - No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing in
- No enclosing instance of type Monster is accessible. Must qualify the allocation with an enclosing i
- redis的定义-form wiki
- Spring Cache使用参考指南
- TCP Nagle算法&&延迟确认机制
- hadoop运行wordcount实例
- Image scaling
- java内部类编译错误 No enclosing instance of type Test03 is accessible. Must qualify the allocation with 。。。
- (POJ
- can't find referenced pointcut annotationPointCut
- Android_xlistview显示轮播头布局
- linux 常用命令(二)
- loadrunner11无法录制脚本
- xgboost学习样例解析之binary classification
- 大写 字母转换成相应小写字母
- RGB颜色空间与Lab颜色空间区别与联系(附转换代码)