问题描述
如何启用运行时调试Notch正在在Eclipse中?
How can I enable this "Debugging in Runtime" Notch is talking about in this video in Eclipse?
作为测试,我希望能够编辑以下代码的输出,并将其更改为Hello Runtime Debugging而且它正在运行。
As a test, I'd like to be able to edit the output of the following code and change it to "Hello Runtime Debugging" while it's running.
public class HelloWorld {
public static void main(String[] args) throws InterruptedException {
doIt();
}
private static void doIt() throws InterruptedException {
for (int i = 0; i < 1000; ++i) {
System.out.println("Hello World " + i);
Thread.currentThread().sleep(100);
}
}
}
编辑:我修改了代码,现在我得到了我正在寻找的结果。 Suraj Chandran的回答如下:
I modified the code, now I get the results I was looking for. Suraj Chandran's answer below explains it.
private static void doIt() throws InterruptedException {
for (int i = 0; i < 1000; ++i) {
print(i);
Thread.currentThread().sleep(100);
}
}
private static void print(int i) {
System.out.println("Hello Sir " + i);
}
推荐答案
Eclipse支持热插拔代码调试,开箱即用。
Eclipse supports hot swapping code during debugging , out of the box.
调试时,只需更改任何代码并保存,eclipse将自动将修改的代码传输到目标VM。
While debugging, just change any code and save it, eclipse will automatically transfer the modified code to the target VM.
请注意,您不能对代码进行结构更改,例如添加新方法,更改方法签名或添加新字段。但是您可以在方法中更改代码。
Note that you can't make structural changes to the code, like adding new methods, changing method signature or adding new fields. But you can change the code within a method.
编辑:请注意,在卸载期间更改代码将使该方法从头开始重新执行,重置局部变量那个方法。
Note that changing the code during deubgging will make that method re-execute form the beginning, resetting the local variables in that method.
这篇关于在调试模式下运行时如何修改java代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!