为什么静态嵌套类无法访问"this"?外层阶级的指针? [英] Why can't a static nested class access "this" pointer of outer class?

查看:120
本文介绍了为什么静态嵌套类无法访问"this"?外层阶级的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

困扰我的是第二点.

我认为这可能与"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"?外层阶级的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆