Question
How to inspect the value returned by a getter (or any other method) during a Java debugging session in IntelliJ IDEA, without stepping into the method or evaluating each call by hand.
Answer
IntelliJ IDEA provides the following debugger features for this:
Show Method Return Values
This option displays the value returned by the last executed method directly in the Variables view, so the result is visible after stepping over a call instead of stepping into it.
To enable it, open the Debug tool window, click More (the ⋮ menu) on the toolbar, and select Debugger Settings | Show Method Return Values. After stepping over a line that calls a getter or method, the returned value appears in the Variables view.
This shows the return values of methods executed during the most recent step.
Note: It can affect stepping performance; disable it if stepping becomes slow.
Skip simple getters
When the goal is to avoid stepping into trivial getters rather than display their values, enable Skip simple getters in Settings | Build, Execution, Deployment | Debugger | Stepping (Ctrl+Alt+S). Step Into then passes over simple getter methods. This option does not display getter values; it only suppresses stepping into them.
Evaluate Expression and Watches
For ad-hoc inspection of a specific getter, use Evaluate Expression or add the getter call as a Watch in the debugger. Both evaluate the expression on demand and show the result.
For more details, see Step through the program in the IntelliJ IDEA documentation. You can also vote for the feature requestIDEA-270955 to prioritise it.
Comments
0 comments
Please sign in to leave a comment.