Java 在 Eclipse 中,在调试时,如何访问交互式顶级(也称为“显示控制台”)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/871403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:29:15  来源:igfitidea点击:

In eclipse, while debugging, how do I access the interactive-top-level (a.ka. the "display console")?

javaeclipse

提问by Aaron Fi

In most programming languages I've used, when debugging, when I hit a breakpoint, I have the ability to execute arbitrary code (whatever I type into the console after the breakpoint has been hit).

在我使用过的大多数编程语言中,在调试时,当我遇到断点时,我有能力执行任意代码(无论我在断点被命中后在控制台中输入什么)。

How do I do this in Eclipse? The debugging mode has, by default, a display console, but no interactive console (into which I can input Java code for immediate execution)

我如何在 Eclipse 中执行此操作?默认情况下,调试模式有一个显示控制台,但没有交互式控制台(我可以在其中输入 Java 代码以立即执行)

采纳答案by Jon

You can use the Display view to execute arbitrary code, access it via:

您可以使用 Display 视图执行任意代码,通过以下方式访问它:

window->Show View->Display

窗口->显示视图->显示

then type the code you want to execute (you can use CTRL+SPACEfor autocomplete).

然后键入要执行的代码(可CTRL+SPACE用于自动完成)。

to execute the code, select it then:

要执行代码,请选择它然后:

CTRL+SHIFT+D

CTRL+SHIFT+D

That should execute the code based on the breakpoint you've hit.

那应该根据您命中的断点执行代码。

alt text

替代文字

Note: As of 2018, Display View has been renamed to Debug Shell View.

注意:截至 2018 年,Display View 已重命名为Debug Shell View

回答by digitalbreed

Eclipse has it indeed. Window->Show View->Interactive Console. Note that you can also execute expressions in the Watch view (e.g. result=false, exception.printStackTrace() etc.).

Eclipse 确实有它。窗口->显示视图->交互式控制台。请注意,您还可以在 Watch 视图中执行表达式(例如 result=false、exception.printStackTrace() 等)。