在《thinking in java》内部类有关链接到外部类的章节,有这么一段话:
要想直接创建内部类的对象,你不能按照你想要的方式,去引用外部类的名字DotNew,而是必须使用外部类的对象来创建该内部类的对象。即:
DotNew dn = new DotNew();
DotNew.Inner inner = dn.new Inner();
这也解决了内部类名字作用域的问题,因此你不能声明(实际上你不能声明)dn.new DotNew.Innter();
这其中提到的内部类名字的作用域的问题
是什么意思?
Here mainly refers to:
Since the inner class scope must rely on a clear outer class, the relationship between the inner class and the outer class must be grammatically clear.
dn.new Inner(); This syntax can clearly indicate that dn (the external class) has new an Inner() (inner class) object, and this object must rely on the dn object.
dn.new DotNew.Inner(); If you use this syntax, then it doesn’t matter whether it is dn or not, it can even be replaced by xxx.new DotNew.Inner(); or it can even be replaced by new DotNew.Inner( ); It feels like this Inner has little to do with who gets the new one.
Of course, this is just me reading such a sentence and trying to figure out what the author wants to express. It may not be correct.