以下代码段的含义是什么?

Ada*_*Lee 0 java

 TestClass.this.onError(error);
Run Code Online (Sandbox Code Playgroud)

我认为这是java中的关键工具,类名如何跟随它呢?这是java的一个特殊功能吗?

Jon*_*eet 9

这是一种从内部类中访问封闭类的隐式实例的方法.例如:

public class Test {

    private final String name;

    public Test(String name) {
        this.name = name;
    }

    public static void main(String[] args) {
        Test t = new Test("Jon");
        // Create an instance of NamePrinter with a reference to the new instance
        // as the enclosing instance.
        Runnable r = t.new NamePrinter();
        r.run();
    }    

    private class NamePrinter implements Runnable {
        @Override public void run() {
            // Use the enclosing instance's name variable
            System.out.println(Test.this.name);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有关内部类和封闭实例的更多信息,请参阅Java语言规范部分8.1.3 ;有关"限定"表达式的部分请参见第15.8.4节this:

任何词汇封闭的实例(第8.1.3节)都可以通过明确限定关键字this来引用.

我们C要记类ClassName.设n是一个整数,这样C就是该类表达式出现的类的第n个词汇封闭类.

表单的表达式的值ClassName.this是第n个词汇封闭的实例.

表达式的类型是C.