Java 在eclipse中调试时实时更改变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3778217/
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-14 04:52:55  来源:igfitidea点击:

Changing variables in realtime when debugging in eclipse?

javaeclipsedebuggingtesting

提问by Julio

Using Eclipse, when debugging is it possible to change the value of variables during runtime of a project for testing purposes.

使用 Eclipse,调试时可以在项目运行期间更改变量的值以进行测试。

For example, say I have a method that returns the number 5 but for testing purposes i want to output 10 instead. This isn't the problem I'm facing its a little more complex but its just to get my idea across.

例如,假设我有一个返回数字 5 的方法,但出于测试目的,我想输出 10。这不是我面临的问题,它有点复杂,但只是为了传达我的想法。

采纳答案by aioobe

You should be able to set a break-point, go into debug mode, open the variables views and here change the content of the variables.

您应该能够设置断点、进入调试模式、打开变量视图并在此处更改变量的内容。

enter image description here

在此处输入图片说明

回答by Colin Hebert

You can access variables through the Variables view. There you can right click on any variable and select "Change value ...".

您可以通过变量视图访问变量。在那里您可以右键单击任何变量并选择“更改值...”。



Resources :

资源 :

回答by Gadolin

... and you can do much, much more:-) Just to give you and idea.
You may change the code during debug which is hot swapped and is effectively changed (recompiled) in given debug session. You may run given method run (e.g. after catching breakpoint) few times without rerunning debug -> use drop to frame feature on method stack.

......你可以做很多很多:-) 只是给你和想法。
您可以在调试期间更改热交换的代码,并在给定的调试会话中有效地更改(重新编译)。您可以在不重新运行调试的情况下多次运行给定的方法运行(例如在捕获断点之后)-> 在方法堆栈上使用 drop to frame 功能。

回答by martie

After you have changed the code you have to save it (cntrl-S) to make it effective. You will see your running application respond to the code-change after the cntrl-S

更改代码后,您必须保存 (cntrl-S) 以使其生效。您将看到正在运行的应用程序响应 cntrl-S 后的代码更改

I hope this works for you. it took me some time to figure this out.

我希望这对你有用。我花了一些时间才弄明白这一点。

回答by Gaurav Shubham

Run your application in debug mode then go to variables window. select the parameter then change values according to your requirements. then save (ctrl+s). and go ahead with your changes. Hope this will help.

在调试模式下运行您的应用程序,然后转到变量窗口。选择参数,然后根据您的要求更改值。然后保存(ctrl+s)。并继续您的更改。希望这会有所帮助。

If variables window is missing. then goto eclipse window->show views->variables

如果变量窗口丢失。然后转到eclipse窗口->显示视图->变量