问题描述
困扰我的是第二点.
我认为这可能与"this"指针不是静态的,因此内部类无法访问它有关.我不确定这是否是正确的解释.
I thought it might have to do with the fact that the "this" pointer isn't static and so the inner class can't access it. I'm not sure if that's the right explanation though.
这对我也提出了另一个问题,即在哪里定义了"this"指针?"
This also raised another question for me which was "where is the "this" pointer defined?"
推荐答案
static
嵌套类与非static
的嵌套类之间的区别恰恰是非static
内部类的实例是与封闭类的特定实例相关联,而static
内部类则没有.没有 没有A.this
与要关联的static
内部类的实例.
The difference between a static
nested class and one that isn't static
is precisely that an instance of a non-static
inner class is associated with a specific instance of the enclosing class, while a static
inner class isn't. There is no A.this
for an instance of a static
inner class to be associated with.
这篇关于为什么静态嵌套类无法访问"this"?外层阶级的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!