调试时堆栈帧中的美元符号是什么意思?

2022-09-03 06:15:38

在使用Eclipse的堆栈中,有时我看到

经理$2.run() 行 : 278

$2是什么意思?


答案 1

它是匿名类。

匿名类是没有名称的本地类。匿名类是使用 new 运算符在单个简洁表达式中定义和实例化的。

从方法名称来看,它可能是 Runnable.run() 方法。

public class Manager {
    
    public static void main(String[] args) {
        new Manager();
    }
    
    public Manager() {
        //                         this is anonymous class
        //                              |
        //                              V
        Thread thread = new Thread(new Runnable() {
            
            @Override
            public void run() {
                System.out.println("hi");
            }
        });
        thread.start();
    }
}


答案 2

推荐