of scanAndLockForPut in ConcurrentHashMap in JDK7说:
private HashEntry<K,V> scanAndLockForPut(K key, int hash, V value) {
HashEntry<K,V> first = entryForHash(this, hash);
HashEntry<K,V> e = first;
HashEntry<K,V> node = null;
int retries = -1; // negative while
在下面的代码(HashMap中put方法的实际实现)中,我看到modCount只有在新条目被添加时才会增加,但不确定在替换旧值和为给定键插入新值的正常情况下是否会增加。但我的理解是,当hashmap结构发生变化时,mod计数会增加,也就是说,在添加、删除或更新映射中的值时。有人能解释一下这一点吗,正如我在代码中没有看到的那样,modCount在if部分中增加,而不是在for循环之外增加(所以这仅仅是为了添加一个新的值,这个modCount会改变)吗?
public V put(K key, V value) {
if (key == null)
return putForNullK
我有以下代码
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class Person {
private String name;
private long birthTime;
@Override
public int hashCode() {
return Objects.hash(name, birthTime);
}
@Override
public boolean equals(Object obj) {
if (thi