这个问题主要是关于正确的 Java 术语。
我正在区分与封闭范围实例相关的内部类和独立于封闭范围实例的非内部嵌套静态类。
public class Example {
class Inner {
void f1() {System.out.println(Example.this); } // Inner class can access Example's this
}
static class StaticClass {
void f1() {System.out.println(this); } // Static nested class - Only its own this
}
public static void main(String[] args) {
}
void f1() {
int local=0;
class Local {
void f2() {
System.out.println(Example.this); // Local class - can access Example.this
System.out.println(local); // can access local
}
}
Runnable r = new Runnable() {
@Override
public void run() {
System.out.println(Example.this); // Anonymous local class can access Example.this
System.out.println(local); // can access local
}
};
}
}
这是正确的术语吗?如下所示,所有本地类和所有匿名类也是内部类吗?