gpt4 book ai didi

java - 如果使用强制单步执行,IntelliJ 不显示返回值?

转载 作者:行者123 更新时间:2023-12-02 10:46:59 25 4
gpt4 key购买 nike

我正在使用IntelliJ,只是想知道当我们使用Force Step Into调试程序时,返回值没有显示在变量面板。我已启用显示方法返回值选项。 enter image description here

示例:

    import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

class Main {
public static void main(String[] args) {
Map<String, String> map = new HashMap<String, String>();
map.put("Key", "Value");


Iterator<String> itr = map.keySet().iterator(); // Debug this line

while (itr.hasNext()) {
System.out.println(itr.next());
}
}
}

调试 A(使用强制步入 + 步出):我刚刚单击了强制步入一次enter image description here ,然后单击一次退出 enter image description here ,我们可以看到keySet()返回值(主框架):

enter image description here

但是,

调试 B 如果我们不使用步出,只需继续按强制步入 enter image description here走出去 enter image description here 。直到我们运行完最后一行代码:

enter image description here

变量面板上没有显示返回值(主框架)(ks返回值) >)。

enter image description here

我做错了什么吗?

<小时/>

最佳答案

我试图在我的 IntelliJ 中复制你正在做的事情。我发现,如果您使用“调试 B”选项,如果您继续点击“强制步入”,那么 IntelliJ 会继续挖掘得越来越深,程序控制返回到返回值的点将需要很长时间在主要方法中。然而,作为一个非常有耐心的人,我经历了这一过程,发现最终控制权确实回到了 main 方法,然后你将在变量面板中看到返回值。

我从这个练习中得到的结论是,如果 IntelliJ 有有关返回值的信息,那么它会显示在调试控制台中。为了让 IntelliJ 获取该信息,它需要等待代码块完成执行。通过“强制步入”,代码块需要更长的时间来执行,因此我们不会立即看到返回值。然而,通过执行“step out”,代码块完成并且我们看到返回值。

希望这有帮助!

关于java - 如果使用强制单步执行,IntelliJ 不显示返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52472395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com