在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  Python  網(wǎng)絡(luò)安全/ HashMap的無參構(gòu)造函數(shù)是如何構(gòu)造初始容量為16的容器的?

HashMap的無參構(gòu)造函數(shù)是如何構(gòu)造初始容量為16的容器的?

HashMap無參構(gòu)造函數(shù)如下:

    /**
     * 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
    }

它是如何像它Javadoc中說的一樣構(gòu)造了一個(gè)初始容量為16的容器的?Node數(shù)組都不用初始化的么?至少加上一句

table = new Node<>[DEFAULT_INITIAL_CAPACITY];

才合乎常理吧!
請各位賜教!

回答
編輯回答
忠妾

注釋說了在第一次使用的時(shí)候才會初始化

  /**
     * 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;

初始化代碼在 final Node<K,V>[] resize() 方法里面,


     Node<K,V>[] newTab = (Node<K,V>[])new Node[newCap];
     table指向這個(gè)newTab
2017年3月5日 04:56