这是一个更具体的例子:
public class A {
public static class B {
public void f() {
synchronized (B.this) {
// do something
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
B.this指的是什么?
It's the active instance ofB . If the class weren't static, you'd also haveA.this`可用,引用包含A的实例.
因为类是静态的,所以永远不需要使用它B.this,因为它永远this不会是模棱两可的.