简体   繁体   English

如何在Eclipse中的foreach循环中使用条件断点?

[英]How to use conditional breakpoint for foreach-loop in eclipse?

I want to know how to use a conditional breakpoint in eclipse. 我想知道如何在日食中使用条件断点。 I have a code like: 我有一个类似的代码:

for(A a:aList){}

I have already put a breakponit on the line and I have setted the condition 我已经在网上设置了一个断头台,并设置了条件

a.getXxx.equals("yyy")

but eclipse show me a error: 但是日食给我看一个错误:

Conditional breakpoint has compliation error(s).
Reason:
a cannot be resolved

please help me find the reason. 请帮助我找到原因。

you have to place the breakpoint in the first row within in the loop, as a will not be known on the line of the loop yet. 您必须将断点放置在循环的第一行中,因为在循环的行中尚不知道a。 So for 因此对于

List<Object> myObjects = ...;
for (Object obj : myObjects ) {
    obj.doSth();
}

you would place the breakpoint on the line which is " obj.doSth(); " 您可以将断点放在“ obj.doSth(); ”行上

This is actually due to the fact that for the foreach loop the compiler does nothing else than a call to the Iterator.next(); 这实际上是由于以下事实:对于foreach循环,编译器只对Iterator.next()进行了调用。 method as the first statement in the loop (you wont notice that as the compiler does it automatically). 方法作为循环中的第一条语句(您不会注意到编译器会自动执行该操作)。 Have a look at the java spec: http://docs.oracle.com/javase/specs/jls/se5.0/html/statements.html#14.14.2 看看Java规范: http : //docs.oracle.com/javase/specs/jls/se5.0/html/statements.html#14.14.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM