Reputation: 21
So I updated to Eclipse Mars (4.5) and for some reason I'm unable to use the hot swap code in the debugger. Normally I could do something like this:
public static void main(String[] args){
while(true){
System.out.println("123");
}
}
Then if I started it in debug mode, changed the text to "321", then save, then it would update without the need for restarting it. It behaves exactly like it was run in "Run" mode instead of "Debug".
What I have tried:
I'm starting to get desperate as I have a hard time getting work done without having debug mode available so any help/hints in the right direction would be of much appreciation.
Upvotes: 1
Views: 713
Reputation: 21
Ok so I finally found the problem. It seems that you can't edit loops while they are running. Say you have a loop like this:
public static void main(String[] args){
while(true){
System.out.println("123");
}
}
Then you can't edit the "123" string. You can how ever edit methods which are called inside the loop like this:
public static void main(String[] args){
while(true){
System.out.println(methodA());
}
}
public static String methodA(){
return "123";
}
Now you can edit the string "123" and it will update. This also applies for infinite "for" loops, so guess the rule of thumb is that the method body has to be "re-called" before updating, and it isn't enough to wait for the next loop call.
Upvotes: 1
Reputation: 5502
HotSwap doesn't work with static methods.
However it works fine with instance methods, so it will work on this code:
public class Main {
public static void main(String[] args) {
new Main().f();
}
public void f() {
while(true){
System.out.println("123");
}
}
}
Upvotes: 1