么是封闭实例-呵呵,这个概念我第一次看见是在一本叫做Java高效编程的书上,于是baidu,google都没有找到相关的网页。
后来无意中想起来了我看英文书中的enclosing class,推断这个译本的原文应该是enclosing instance,果不其然,上网一搜发现好多人再问no enclosing instance of class XXX的问题,不禁郁闷了一把,心想学java的兄弟第一次见到汉语的封闭类会不会也像我一样郁闷呢,所以决定写这篇贴备我以后查阅也希望能帮到需要的其他人。重新再次声明:“我的日志并不是想有人想像的那样叫做什么显摆用的,呵呵”!
(1)enclosing class
Java中把定义在其他类内部的类定义为Inner class,相反包含Inner class的类被叫做该Inner class的enclosing class。
(2)enclosing instance
有了上面关于enclosing class的定义,很容易就明白enclosing instance就是它的实例(instance)。
(3)no enclosing instance of class XXX
为了解释这个runtime exception,我首先假设有以下的类定义:
public class Outter {
public class Inner {
private int value;
}
public void testInnerClass () {
_______________________________
//如何声明一个指向内部类实例的应用变量呢?
}
}
其实,只要对实例变量和类变量理解的够深刻,你就应该很轻松的在上面的横线填入以下代码:
Outter.Inner oi = new Outter.Inner();
or Inner oi = new Inner();
or Outter.Inner oi = new Outter().new Inner();
Jvm对于这三种答案都是认同的,但是你别高兴得太早,想象如果不是在enclosing class中的情形
又如何呢?
那么只能是最后一个答案,我曾看见有人写过下面的方法:
Outter.Inner oi = new Outter.Inner();
这时就会抛出上面的异常信息了,呵呵,其实想想Inner不是static的,怎么可以通过enclosing class
的类名引用呢?
分享到:
相关推荐
主要介绍了Java解决No enclosing instance of type PrintListFromTailToHead is accessible问题的两种方案的相关资料,需要的朋友可以参考下
编辑 Select Enclosing Element Alt+Shift+向上键 Editing in Structured Text Editors 编辑 选择外层元素 Alt+Shift+向上键 编辑 Java 源代码 编辑 Restore Last Selection Alt+Shift+向下键 Editing in Structured...
本程序主要用于求解小圆覆盖大圆问题,本文求解过程中优先选择蜂窝状正六边形网格法求解。若正六边形网格不能恰好完整覆盖目标,此时,需要先采用圆周覆盖法将大圆圆周完整覆盖,再对大圆中心区域填补的方法,填补时...
2.1.static nested class访问enclosing class(outer class)的成员 2.2.enclosing class(outer class)访问static nested class的成员 3.Non-static nested classes(Inner classes) 3.1.Non-Static Inner ...
在线图片编辑 图片可拖动 裁剪区固定中间 有预览区 项目中应用
主要介绍了Android 中LayoutInflater.inflate()方法的介绍的相关资料,希望通过本文大家能掌握这部分内容,需要的朋友可以参考下
对CDatabase和CRecordSet的改写
Android Studio升级到哦最新版3.6.1后,新建了个项目,发现无法执行Java类的main方法。试了网上的各种方法,比如切换gradle离线模式、gradle.properties中添加android.enableAapt2=false等,我还尝试了重新情况...
thus an intractable preprocessing of enclosing blob gaps is necessary. Loy and B
函数的作用域 python中的作用域分4种情况: L:local,局部作用域,即函数中定义的变量; E:enclosing,嵌套的...local和enclosing是相对的,enclosing变量相对上层来说也是local。 作用域产生 在Python中,只有模
主要介绍了Eclipse新建项目不可选择Java Project问题解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
screen enclosing the power source and the work complete with associated input filters. In all cases electromagnetic disturbances must be reduced to the point where they are no longer troublesome.
Image registration procedures, Multimodality non-rigid registration, the effect is obvious, enclosing the test sample
msp430 UART test program, beginners essential for college students SCM contest entry procedures, enclosing the source, and Chinese comments
(Center-Constrained Minimal Enclosing Ball,CCMEB)理论提出了大数据集快速谱聚类算法CCMEB-CGRC.该算法继承GRC 的便捷性和自适应性的同时又具有渐近线性时间复杂度的优点,从而较好地解决了大数据集快速有效谱聚类...
E:enclosing函数内部与内嵌函数之间 G:global全局作用域 B:build-in内置作用域 python 闭包 1.Closure:内部函数中对enclosing作用域变量的引用 2.函数实质与属性 函数是一个对象 函数执行完成后内部变量回收...
If the decimal representation has a repeating sequence of digits, indicate the sequence by enclosing it in brackets. For example, 1/3 = .33333333...is denoted as 0.(3), and 41/333 = 0.123123123...is ...
offset ( 100 , 200 )let enclosing = Circle ( 120 ). offset ( 160 , 170 )let circle4 = Circle ( 50 ). offset ( 200 , 150 )visualizer. region = circle1. plus (circle2). intersection (enclosing). minus ...
* @version ${enclosing_type}${tags} * @since JDK 1.6 */ /** * * @Description TODO ADD Description. * ClassName:BaseService * * @Author 刘兆明 * @CreateDate 2015年7月20日 下午3:...
By using and/or opening any packaging enclosing this software, expanding any compressed file containing this software or by utilizing this software, you agree to be bound by the terms of this ...