When debugging in eclipse, I believe you are able to change the value of a variable in the source and have it update in realtime without setting breakpoints or anything. I was wondering if the same was possible in intellij?
-
You'll need to elaborate. How does one manually change a variable without a breakpoint?Christopher Schneider– Christopher Schneider2017-04-18 20:05:27 +00:00Commented Apr 18, 2017 at 20:05
-
if you have a setter you can add it as an evaluate expressionvikingsteve– vikingsteve2017-04-19 12:31:31 +00:00Commented Apr 19, 2017 at 12:31
2 Answers
You can reload classes while running your program in Debug mode and changes in code will apply if possible (there are limitations) without restarting the program.
To reload changed classes
Do one of the following:
- On the main menu, choose Run -> Reload Changed Classes.
- On the main menu, choose Build -> Compile "class_name" to recompile an altered class during debug.
Not aware about any other method to change the value of a variable "in real-time".
2 Comments
Yes, IntelliJ IDEA allows you to see real-time changes while debugging Java code. This feature is called HotSwap, and it allows you to modify your code while the program is running, without the need to stop and restart the debugger.
To use HotSwap in IntelliJ IDEA, you first need to enable it by going to the Run/Debug Configuration dialog and selecting the configuration for your application. Then, in the "Debug" tab, make sure the "Enable HotSwap" option is checked.
To use HotSwap, simply make your code changes in the editor and then press Ctrl+F9 (Windows/Linux) or Command+F9 (macOS) to compile and reload the code in the running program.
Note that not all changes can be applied using HotSwap. Some changes, such as changes to class hierarchies or changes to method signatures, will require a full restart of the debugger. Additionally, HotSwap is not supported in all Java virtual machines, so make sure to check the compatibility of your JVM if you encounter any issues