V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2EX  ›  Angzk3348  ›  全部回复第 9 页 / 共 9 页
回复总数  161
1  2  3  4  5  6  7  8  9  
先来看看
new HashMap<>();
只是初始化了 loadFactor 的值.
====源码====
public HashMap() {
this.loadFactor = DEFAULT_LOAD_FACTOR; // all other fields defaulted
}
====源码====


再来看看
capacity()
因为调用的是 无参构造器.
table 肯定是 null 第一个三目 是 false.
threshold 没赋值 第二个三目 也是 false.
====源码====
final int capacity() {
return (table != null) ? table.length : (threshold > 0) ? threshold :DEFAULT_INITIAL_CAPACITY;
}
====源码====

那么 再来看看
DEFAULT_INITIAL_CAPACITY
====源码====
static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16
====源码====
1  2  3  4  5  6  7  8  9  
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2665 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 9ms · UTC 11:05 · PVG 19:05 · LAX 04:05 · JFK 07:05
♥ Do have faith in what you're doing.