I'm using the IntelliJ, just want to know when we debug a program using the Force Step Into
, the return value
doesn't show up in the Variables
panel. I have enabled the Show Method Return Values
option.
Sample:
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
class Main {
public static void main(String[] args) {
Map<String, String> map = new HashMap<String, String>();
map.put("Key", "Value");
Iterator<String> itr = map.keySet().iterator(); // Debug this line
while (itr.hasNext()) {
System.out.println(itr.next());
}
}
}
Debug A(Using Force Step Into
+ Step Out
): I just clicked the force step into
once, then click the step out
once,they we can see the returned value
(main frame) from keySet()
:
However,
Debug B if we are not using the step out
, just keep pressing the force step into
and step out
. Until we finished running the last line of code:
there is no return value
(main frame) displayed on the Variable
Panel(ks
is the return value
).
Am I doing something wrong?
I tried to replicate what you are doing in my IntelliJ. What i found is that in case of your Debug B option, If you keep hitting "force step into", then IntelliJ keep digging deeper and deeper and it will take a VERY long time before the program control comes back to the point it returns value in the main method. however, being a very patient person, I went through that and found eventually control does come back to main method and then you will see the return value in variables panel.
My takeaway from this exercise is that if IntelliJ has information about return value then it displays in debug console. and in order for IntelliJ to get that information, it needs to wait until the code block completes execution. by "force step into", code block takes longer to execute and so we dont see return value immediately. However, by doing "step out", code block completes and we see return value.
Hope this helps!