![](/img/trans.png)
[英]Finding a webelement always fails while running the code but passes in debug mode
[英]How to modify Java code while running in debug mode?
我怎样才能启用这个“运行时调试”Notch在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将自动将修改后的代码传输到目标VM。
请注意,您无法对代码进行结构更改,例如添加新方法,更改方法签名或添加新字段。 但是您可以在方法中更改代码。
编辑:请注意,在deubgging期间更改代码将使该方法从头开始重新执行,重置该方法中的局部变量。
您需要确保选中Project> Build Automatically 。 否则它可能无法正常工作。
我可能会误解这个问题,但是如果你在Eclipse中以调试模式(Run / Debug)运行程序,你可以在程序运行期间编辑方法的内容(如果JVM支持它)。 通常,您无法更改导入,方法签名,类定义等,只能更改方法的内容。
启用Project-> Build Automatically后,调试模式下的热交换代码对我来说没问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.