假设我有以下类并想在标记位置的 arg==null 上设置条件断点。这在 eclipse 中不起作用,并给出错误“条件断点有编译错误。原因:arg 无法解析为变量”。
我找到了一些相关资料here ,但即使我将条件更改为“val$arg==null”(val$arg 是调试器变量 View 中显示的变量名称),eclipse 也会给我同样的错误。
public abstract class Test {
public static void main(String[] args) {
Test t1 = foo("123");
Test t2 = foo(null);
t1.bar();
t2.bar();
}
abstract void bar();
static Test foo(final String arg) {
return new Test() {
@Override
void bar() {
// I want to set a breakpoint here with the condition "arg==null"
System.out.println(arg);
}
};
}
}
最佳答案
我只能提供一个丑陋的解决方法:
if (arg == null) {
int foo = 0; // add breakpoint here
}
System.out.println(arg);
关于java - 如何根据最终局部变量在匿名内部类中设置条件断点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4733572/