Intellij调试器在foreach循环中找不到本地变量
尝试调试以下块时,我会遇到Intellij的错误:
1. private boolean compareMatrices(Map<String, Map<String, Double> toCompare) {
2. for (String c1 : this.keySet()) {
3. Map<String, Double> thisRow = this.get(c1);
4. Map<String, Double> otherRow = toCompare.get(c1);
5.
6. for (Entry<String, Double> cell : thisRow.entrySet())
7. if (!otherRow.get(cell.getKey()).equals(cell.getValue()))
8. return false;
9. }
10. return true;
11. }
我已经在第7行上放置了一个条件etherrow.get(cell.getKey())== null
并获取“每当点击点击点时,调试器无法找到本地变量单元格”
错误。如果我将For Block(第6-8行)包装在牙套中,则不会发生此错误,因此:
1. private boolean compareMatrices(Map<String, Map<String, Double> toCompare) {
2. for (Stringc1 : this.keySet()) {
3. Map<String, Double> thisRow = this.get(c1);
4. Map<String, Double> otherRow = toCompare.get(c1);
5.
6. for (Entry<String, Double> cell : thisRow.entrySet()) {
7. if (!otherRow.get(cell.getKey()).equals(cell.getValue()))
8. return false;
10. }
10. }
11. return true;
12. }
我的问题是,我可能犯了一个配置错误,还是这确实是与Intellij的误解有关的错误Java语法?另外,有条件的断点是否会大大减慢调试器?使用上面的第二版时,调试器执行正确,但要比正常执行时间长10倍。
I'm getting an error with IntelliJ when attempting to debug the following block:
1. private boolean compareMatrices(Map<String, Map<String, Double> toCompare) {
2. for (String c1 : this.keySet()) {
3. Map<String, Double> thisRow = this.get(c1);
4. Map<String, Double> otherRow = toCompare.get(c1);
5.
6. for (Entry<String, Double> cell : thisRow.entrySet())
7. if (!otherRow.get(cell.getKey()).equals(cell.getValue()))
8. return false;
9. }
10. return true;
11. }
I have placed a breakpoint on Line 7 with the condition otherRow.get(cell.getKey()) == null
and get the "Cannot find local variable cell"
error from the debugger whenever the breakpoint is hit. That error does not happen if I enclose the for block (Lines 6-8) in braces, like this:
1. private boolean compareMatrices(Map<String, Map<String, Double> toCompare) {
2. for (Stringc1 : this.keySet()) {
3. Map<String, Double> thisRow = this.get(c1);
4. Map<String, Double> otherRow = toCompare.get(c1);
5.
6. for (Entry<String, Double> cell : thisRow.entrySet()) {
7. if (!otherRow.get(cell.getKey()).equals(cell.getValue()))
8. return false;
10. }
10. }
11. return true;
12. }
My question is, is the error coming from a configuration mistake I may have made, or is this really a bug relating to IntelliJ's misinterpretation of Java syntax? Also, do conditional breakpoints significantly slow down the debugger? When using the second version above, the debugger executes correctly, but takes over ten times longer than in normal execution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码是有效的Java,因此它不能是配置错误。我怀疑这是一个Intellij错误。我的猜测是您:
用存在的括号编译了程序
以调试模式运行程序
删除括号
执行的括号
,现在您的源代码与编译后的代码不匹配,因此错误。
停止执行,再次使用代码的第一个版本构建项目,然后尝试再次调试。
是的,有可能。场和方法断点也比“常规”的断点明显慢。
Your code is valid java thus it cannot be a configuration mistake. I doubt that it's an IntelliJ bug. My guess is that you:
compiled the programm with the brackets present
run the program in debug mode
removed the brackets
executed the line with the breakpoint
and now your source code doesn't match the compiled one, hence the error.
Stop the execution, build your project again with the first version of the code and try debugging it again.
Yes, it's possible. Field and method breakpoints are also significantly slower than "regular" ones.