小编use*_*600的帖子

无法理解在ConcurrentHashMap中重写equals方法的实现的优势

Java中的大多数映射类都会覆盖AbstractMap并使用它的equals方法实现来检查:

  1. 传递的对象是Map类型
  2. 长度相同
  3. 包含所有条目 this

    if (o == this)
        return true;
    
    //check that passed object is of type Map
    if (!(o instanceof Map))
        return false;
    Map<?,?> m = (Map<?,?>) o;
    
    //check that passed object has same length
    if (m.size() != size())
        return false;
    
    //passed object contains all the entries
    try {
        Iterator<Entry<K,V>> i = entrySet().iterator();
        while (i.hasNext()) {
            Entry<K,V> e = i.next();
            K key = e.getKey();
            V value = e.getValue();
            if (value == null) {
                if …
    Run Code Online (Sandbox Code Playgroud)

java java.util.concurrent

14
推荐指数
1
解决办法
157
查看次数


标签 统计

git ×1

github ×1

java ×1

java.util.concurrent ×1