如何启用 Notch 在 this video 中谈论的“运行时调试”在 Eclipse 中?
作为测试,我希望能够编辑以下代码的输出,并在其运行时将其更改为“Hello Runtime Debugging”。
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 在下面的回答对此进行了解释。
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 会自动将修改后的代码传输到目标虚拟机。
请注意,您不能对代码进行结构更改,例如添加新方法、更改方法签名或添加新字段。但是您可以在方法内更改代码。
编辑:请注意,在调试期间更改代码将使该方法从头开始重新执行,并重置该方法中的局部变量。
关于java - 如何在 Debug模式下运行时修改 Java 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12661114/