在 Effective Java在“第 22 项:优先考虑静态成员类而不是非静态”项中,Josh Bloch 说:
Each instance of a nonstatic member class is implicitly associated with an enclosing instance of its containing class. Within instance methods of a nonstatic member class, you can invoke methods on the enclosing instance or obtain a reference to the enclosing instance using the qualified this construct.
他说的合格的这个构造是什么意思?
最佳答案
没有限定符,x()
将递归。使用限定符,将调用封闭实例的 x()
方法。
class Envelope {
void x() {
System.out.println("Hello");
}
class Enclosure {
void x() {
Envelope.this.x(); /* Qualified*/
}
}
}
关于java - java中的 "qualified this"构造是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11276994/