如何根据最终局部变量在匿名内部类中设置条件断点?
假设我有以下类,并且想要在标记位置的 arg==null 上设置条件断点。这在 Eclipse 中不起作用,并给出错误“条件断点有编译错误。原因:arg 无法解析为变量”。
我在此处找到了一些相关信息,但即使我将条件更改为“val$arg== null”(val$arg是调试器变量视图中显示的变量名),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);
}
};
}
}
suppose I have the following class and want to set a conditional breakpoint on arg==null at the marked location. This won't work in eclipse and gives the error "conditional breakpoint has compilation error(s). Reason: arg cannot be resolved to a variable".
I found some related information here, but even if I change the condition to "val$arg==null" (val$arg is the variable name displayed in the debugger's variable view), eclipse gives me the same error.
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);
}
};
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只能提供一个丑陋的解决方法:
I can only offer an ugly workaround:
您可以尝试将参数作为本地类中的字段。
You could try placing the argument as a field in the local class.