Home > OS >  Intellij Debugger Display behavior
Intellij Debugger Display behavior

Time:08-25

I am curious about how Intellij Debugger decides what to display for Java. Using below code as an example.

public class App {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("A", "ValA");
        map.put("B", "ValB");
        Collection values = map.values();
        System.out.println(values);
    }
}

When I called map.values(), it returned a Collection type. Looking into code inside HashMap class, we can see values method actually return a final class called Values which extends AbstractCollection class, with an empty constructor inside AbstractCollection class, as shown below

protected AbstractCollection() {
}

However, if I added breakpoint to System.out.println line, the Intellij debugger displays values variable like below (circled in red).How does the debugger get the data "ValA", "ValB" from Values class? Is the debugger have tailored-made implementation for each default Java Classes to display proper values? enter image description here

CodePudding user response:

When you hit the breakpoint on the line of Sysytem.out.println(), it proves that the code of your current thread has been completely executed before this line, and all your values have been saved in the Collection, so idea can recognize .

  • Related