How does the no-parameter constructor of HashMap construct a container with an initial capacity of 16?

The

HashMap no-parameter constructor is as follows:

    /**
     * Constructs an empty <tt>HashMap</tt> with the default initial capacity
     * (16) and the default load factor (0.75).
     */
    public HashMap() {
        this.loadFactor = DEFAULT_LOAD_FACTOR; // all other fields defaulted
    }

how does it construct a container with an initial capacity of 16, as it says in its Javadoc? Doesn"t the Node array have to be initialized? Add at least one sentence

table = new Node<>[DEFAULT_INITIAL_CAPACITY];

is only reasonable!
Please give us your advice!

Apr.02,2021

The

comment says that it will be initialized only when it is used for the first time

  /**
     * The table, initialized on first use, and resized as
     * necessary. When allocated, length is always a power of two.
     * (We also tolerate length zero in some operations to allow
     * bootstrapping mechanics that are currently not needed.)
     */
    transient Node<K,V>[] table;

initialization code is found in the final Node < KJournal V > [] resize () method,


     Node<K,V>[] newTab = (Node<K,V>[])new Node[newCap];
     tablenewTab
Menu