我该如何启用这个“运行时调试”Notch在Eclipse中提到this video?如何在调试模式下运行时修改java代码?
作为一个测试,我希望能够编辑以下代码的输出,并在运行时将其更改为“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);
}
你是怎么做到的?我把一个断点,让我们说,当循环计数是在23,它是“Hello World 22”“Hello World 23”我将文本更改为别的东西,我按简历,现在我得到“你好别的0”它重新启动程序?突然间,这个数字为0。 –
它会重新启动程序,它将从开始重新执行当前方法。所以它会重新设置所有变量 –
啊,解释它。你介意把它放在答案中吗? –