我該如何啓用這個「運行時調試」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。 –
它會重新啓動程序,它將從開始重新執行當前方法。所以它會重新設置所有變量 –
啊,解釋它。你介意把它放在答案中嗎? –