【问题标题】:what is dollar sign mean in the stack frames when debugging?调试时堆栈帧中的美元符号是什么意思?
【发布时间】:2012-06-16 14:35:24
【问题描述】:

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

Manager$2.run() 行:278

$2 在这里是什么意思?

【问题讨论】:

  • 每次创建匿名类 java 都会自动为其命名。 Manager$2Manager 类中的一些匿名类

标签: java eclipse


【解决方案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();
    }
}

【讨论】:

  • @DaveNewton 没有任何东西可以运行。它必须是匿名的
猜你喜欢
  • 2020-01-20
  • 1970-01-01
  • 1970-01-01
  • 2017-07-22
  • 1970-01-01
  • 2018-08-08
  • 1970-01-01
  • 2011-08-09
  • 2020-09-22
相关资源
最近更新 更多