/**
* Implements Map.putAll and Map constructor.
*
* @param m the map
* @param evict false when initially constructing this map, else
* true (relayed to method afterNodeInsertion).
*/
final void putMapEntries(Map<? extends K, ? extends V> m, boolean evict) {
int s = m.size();
if (s > 0) {
if (table == null) { // pre-size
float ft = ((float)s / loadFactor) + 1.0F;
int t = ((ft < (float)MAXIMUM_CAPACITY) ?
(int)ft : MAXIMUM_CAPACITY);
if (t > threshold)
threshold = tableSizeFor(t);
}
else if (s > threshold)
resize();
for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) {
K key = e.getKey();
V value = e.getValue();
putVal(hash(key), key, value, false, evict);
}
}
}
float ft = ((float)s / loadFactor) + 1.0F;此处为什么要加1.0F?
s为键值对数量,s/loadFactor是保证不扩容的情况下计算的所需最小容量capacity,因为结果为浮点型,如11/0.75=14.666667,下面将ft强转为int类型(int)ft,结果为14,为保证不扩容元素都能放得下因此需要加1。