Java集合类源码分析(六):AbstractMap类

从源码分析:Java中的Map(一)Map接口与AbstractMap抽象类 HashMap的继承结构 Java中,我们最常用的map类型可能就是HashMap了,这一次介绍的重点也在HashMap上面。但是,在我们详细分析HashMap之前,我们先来看一下HashMap的继承结构: Java中的Map接口 从上面的继承结构中,可以看出,Java中的HashMap是接口Map的一个实现类,因此,在我们分析HashMap之前,不妨先来看看Map接口。 首先,我们来看一下Ma... 阅读详情

我的github:xjwhhh的github
希望大家多多关注,共同进步

Java集合类源码分析(一):Collcetion接口
Java集合类源码分析(二):List接口
Java集合类源码分析(三):AbstractList类
Java集合类源码分析(四):ArrayList&LinkedList
java集合类源码分析(五):Map接口
Java集合类源码分析(六):AbstractMap类
Java集合类源码分析(七):HashMap&LinkedHashMap
Java集合类源码分析(八):AbstractSet类
Java集合类源码分析(九):HashSet&LinkedHashSet

AbstractMap源码解析

提供了对Map接口大致性的实现

如果要实现一个不可修改的map,只需要继承此类并实现entrySet方法。这个set不支持add,remove,它的迭代器也不支持remove

如果要实现一个可修改的map,还要额外重写这个类的put,迭代器也要实现remove

public boolean containsValue(Object value) {
    Iterator<Entry<K,V>> i = entrySet().iterator();
    if (value==null) {
        while (i.hasNext()) {
            Entry<K,V> e = i.next();
            if (e.getValue()==null)
                return true;
        }
    } else {
        while (i.hasNext()) {
            Entry<K,V> e = i.next();
            if (value.equals(e.getValue()))
                return true;
        }
    }
    return false;
}

使用迭代器遍历entrySet,寻找对应的值与给定参数value相同的键值对

public boolean containsKey(Object key) {
    Iterator<Map.Entry<K,V>> i = entrySet().iterator();
    if (key==null) {
        while (i.hasNext()) {
            Entry<K,V> e = i.next();
            if (e.getKey()==null)
                return true;
        }
    } else {
        while (i.hasNext()) {
            Entry<K,V> e = i.next();
            if (key.equals(e.getKey()))
                return true;
        }
    }
    return false;
}

使用迭代器遍历entrySet,寻找键与给定参数key相同的键值对

public V get(Object key) {
    Iterator<Entry<K,V>> i = entrySet().iterator();
    if (key==null) {
        while (i.hasNext()) {
            Entry<K,V> e = i.next();
            if (e.getKey()==null)
                return e.getValue();
        }
    } else {
        while (i.hasNext()) {
            Entry<K,V> e = i.next();
            if (key.equals(e.getKey()))
                return e.getValue();
        }
    }
    return null;
}

使用迭代器遍历entrySet,寻找键与给定参数key相同的键值对,返回对应的值

public V remove(Object key) {
    Iterator<Entry<K,V>> i = entrySet().iterator();
    Entry<K,V> correctEntry = null;
    if (key==null) {
        while (correctEntry==null && i.hasNext()) {
            Entry<K,V> e = i.next();
            if (e.getKey()==null)
                correctEntry = e;
        }
    } else {
        while (correctEntry==null && i.hasNext()) {
            Entry<K,V> e = i.next();
            if (key.equals(e.getKey()))
                correctEntry = e;
        }
    }

    V oldValue = null;
    if (correctEntry !=null) {
        oldValue = correctEntry.getValue();
        i.remove();
    }
    return oldValue;
}

遍历entrySet,寻找与给定参数key相同的键,如果找到,就调用迭代器的remove将该entry删除,返回对应的值,否则返回null

public V put(K key, V value) {
    throw new UnsupportedOperationException();
}

public void putAll(Map<? extends K, ? extends V> m) {
    for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
        put(e.getKey(), e.getValue());
}

迭代参数map,依次调用put方法

transient Set<K>        keySet;
transient Collection<V> values;

public Set<K> keySet() {
    Set<K> ks = keySet;
    if (ks == null) {
        ks = new AbstractSet<K>() {
            public Iterator<K> iterator() {
                return new Iterator<K>() {
                    private Iterator<Entry<K,V>> i = entrySet().iterator();

                    public boolean hasNext() {
                        return i.hasNext();
                    }

                    public K next() {
                        return i.next().getKey();
                    }

                    public void remove() {
                        i.remove();
                    }
                };
            }

            public int size() {
                return AbstractMap.this.size();
            }

            public boolean isEmpty() {
                return AbstractMap.this.isEmpty();
            }

            public void clear() {
                AbstractMap.this.clear();
            }

            public boolean contains(Object k) {
                return AbstractMap.this.containsKey(k);
            }
        };
        keySet = ks;
    }
    return ks;
}

在KeySet方法第一次被调用时,创建这个set,该方法没有锁

public Collection<V> values() {
    Collection<V> vals = values;
    if (vals == null) {
        vals = new AbstractCollection<V>() {
            public Iterator<V> iterator() {
                return new Iterator<V>() {
                    private Iterator<Entry<K,V>> i = entrySet().iterator();

                    public boolean hasNext() {
                        return i.hasNext();
                    }

                    public V next() {
                        return i.next().getValue();
                    }

                    public void remove() {
                        i.remove();
                    }
                };
            }

            public int size() {
                return AbstractMap.this.size();
            }

            public boolean isEmpty() {
                return AbstractMap.this.isEmpty();
            }

            public void clear() {
                AbstractMap.this.clear();
            }

            public boolean contains(Object v) {
                return AbstractMap.this.containsValue(v);
            }
        };
        values = vals;
    }
    return vals;
}

在Values方法第一次被调用时,创建这个集合,该方法没有锁

public abstract Set<Entry<K,V>> entrySet();    

public boolean equals(Object o) {
    if (o == this)
        return true;//判断是不是原map

    if (!(o instanceof Map))
        return false;//判断参数对象的类型
    Map<?,?> m = (Map<?,?>) o;
    if (m.size() != size())
        return false;//判断长度是否相等

    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 (!(m.get(key)==null && m.containsKey(key)))
                    return false;
            } else {
                if (!value.equals(m.get(key)))
                    return false;
            }
        }
    } catch (ClassCastException unused) {
        return false;
    } catch (NullPointerException unused) {
        return false;
    }//遍历,看entrySet是否相同

    return true;
}

两个map相等当且仅当m1.entrySet().equals(m2.entrySet())

public int hashCode() {
    int h = 0;
    Iterator<Entry<K,V>> i = entrySet().iterator();
    while (i.hasNext())
        h += i.next().hashCode();
    return h;
}

返回map的哈希值,是所有entry的哈希值之和,确保m1.equals(m2)能推出m1.hashCode()==m2.hashCode()

protected Object clone() throws CloneNotSupportedException {
    AbstractMap<?,?> result = (AbstractMap<?,?>)super.clone();
    result.keySet = null;
    result.values = null;
    return result;
}

浅拷贝

public static class SimpleEntry<K,V>
    implements Entry<K,V>, java.io.Serializable
{
    private static final long serialVersionUID = -8499721149061103585L;

    private final K key;
    private V value;

    /**
     * Creates an entry representing a mapping from the specified
     * key to the specified value.
     *
     * @param key the key represented by this entry
     * @param value the value represented by this entry
     */
    public SimpleEntry(K key, V value) {
        this.key   = key;
        this.value = value;
    }

    /**
     * Creates an entry representing the same mapping as the
     * specified entry.
     *
     * @param entry the entry to copy
     */
    public SimpleEntry(Entry<? extends K, ? extends V> entry) {
        this.key   = entry.getKey();
        this.value = entry.getValue();
    }

    /**
     * Returns the key corresponding to this entry.
     *
     * @return the key corresponding to this entry
     */
    public K getKey() {
        return key;
    }

    /**
     * Returns the value corresponding to this entry.
     *
     * @return the value corresponding to this entry
     */
    public V getValue() {
        return value;
    }

    /**
     * Replaces the value corresponding to this entry with the specified
     * value.
     *
     * @param value new value to be stored in this entry
     * @return the old value corresponding to the entry
     */
    public V setValue(V value) {
        V oldValue = this.value;
        this.value = value;
        return oldValue;
    }

    /**
     * Compares the specified object with this entry for equality.
     * Returns {@code true} if the given object is also a map entry and
     * the two entries represent the same mapping.  More formally, two
     * entries {@code e1} and {@code e2} represent the same mapping
     * if<pre>
     *   (e1.getKey()==null ?
     *    e2.getKey()==null :
     *    e1.getKey().equals(e2.getKey()))
     *   &amp;&amp;
     *   (e1.getValue()==null ?
     *    e2.getValue()==null :
     *    e1.getValue().equals(e2.getValue()))</pre>
     * This ensures that the {@code equals} method works properly across
     * different implementations of the {@code Map.Entry} interface.
     *
     * @param o object to be compared for equality with this map entry
     * @return {@code true} if the specified object is equal to this map
     *         entry
     * @see    #hashCode
     */
    public boolean equals(Object o) {
        if (!(o instanceof Map.Entry))
            return false;
        Map.Entry<?,?> e = (Map.Entry<?,?>)o;
        return eq(key, e.getKey()) && eq(value, e.getValue());
    }

    /**
     * Returns the hash code value for this map entry.  The hash code
     * of a map entry {@code e} is defined to be: <pre>
     *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
     *   (e.getValue()==null ? 0 : e.getValue().hashCode())</pre>
     * This ensures that {@code e1.equals(e2)} implies that
     * {@code e1.hashCode()==e2.hashCode()} for any two Entries
     * {@code e1} and {@code e2}, as required by the general
     * contract of {@link Object#hashCode}.
     *
     * @return the hash code value for this map entry
     * @see    #equals
     */
    public int hashCode() {
        return (key   == null ? 0 :   key.hashCode()) ^
               (value == null ? 0 : value.hashCode());
    }

    /**
     * Returns a String representation of this map entry.  This
     * implementation returns the string representation of this
     * entry's key followed by the equals character ("<tt>=</tt>")
     * followed by the string representation of this entry's value.
     *
     * @return a String representation of this map entry
     */
    public String toString() {
        return key + "=" + value;
    }

}

public static class SimpleImmutableEntry<K,V>
    implements Entry<K,V>, java.io.Serializable
{
    private static final long serialVersionUID = 7138329143949025153L;

    private final K key;
    private final V value;

    /**
     * Creates an entry representing a mapping from the specified
     * key to the specified value.
     *
     * @param key the key represented by this entry
     * @param value the value represented by this entry
     */
    public SimpleImmutableEntry(K key, V value) {
        this.key   = key;
        this.value = value;
    }

    /**
     * Creates an entry representing the same mapping as the
     * specified entry.
     *
     * @param entry the entry to copy
     */
    public SimpleImmutableEntry(Entry<? extends K, ? extends V> entry) {
        this.key   = entry.getKey();
        this.value = entry.getValue();
    }

    /**
     * Returns the key corresponding to this entry.
     *
     * @return the key corresponding to this entry
     */
    public K getKey() {
        return key;
    }

    /**
     * Returns the value corresponding to this entry.
     *
     * @return the value corresponding to this entry
     */
    public V getValue() {
        return value;
    }

    /**
     * Replaces the value corresponding to this entry with the specified
     * value (optional operation).  This implementation simply throws
     * <tt>UnsupportedOperationException</tt>, as this class implements
     * an <i>immutable</i> map entry.
     *
     * @param value new value to be stored in this entry
     * @return (Does not return)
     * @throws UnsupportedOperationException always
     */
    public V setValue(V value) {
        throw new UnsupportedOperationException();
    }

    /**
     * Compares the specified object with this entry for equality.
     * Returns {@code true} if the given object is also a map entry and
     * the two entries represent the same mapping.  More formally, two
     * entries {@code e1} and {@code e2} represent the same mapping
     * if<pre>
     *   (e1.getKey()==null ?
     *    e2.getKey()==null :
     *    e1.getKey().equals(e2.getKey()))
     *   &amp;&amp;
     *   (e1.getValue()==null ?
     *    e2.getValue()==null :
     *    e1.getValue().equals(e2.getValue()))</pre>
     * This ensures that the {@code equals} method works properly across
     * different implementations of the {@code Map.Entry} interface.
     *
     * @param o object to be compared for equality with this map entry
     * @return {@code true} if the specified object is equal to this map
     *         entry
     * @see    #hashCode
     */
    public boolean equals(Object o) {
        if (!(o instanceof Map.Entry))
            return false;
        Map.Entry<?,?> e = (Map.Entry<?,?>)o;
        return eq(key, e.getKey()) && eq(value, e.getValue());
    }

    /**
     * Returns the hash code value for this map entry.  The hash code
     * of a map entry {@code e} is defined to be: <pre>
     *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
     *   (e.getValue()==null ? 0 : e.getValue().hashCode())</pre>
     * This ensures that {@code e1.equals(e2)} implies that
     * {@code e1.hashCode()==e2.hashCode()} for any two Entries
     * {@code e1} and {@code e2}, as required by the general
     * contract of {@link Object#hashCode}.
     *
     * @return the hash code value for this map entry
     * @see    #equals
     */
    public int hashCode() {
        return (key   == null ? 0 :   key.hashCode()) ^
               (value == null ? 0 : value.hashCode());
    }

    /**
     * Returns a String representation of this map entry.  This
     * implementation returns the string representation of this
     * entry's key followed by the equals character ("<tt>=</tt>")
     * followed by the string representation of this entry's value.
     *
     * @return a String representation of this map entry
     */
    public String toString() {
        return key + "=" + value;
    }

}

内部Entry类的实现

Starlink第三代终端和第二代终端的差异性有哪些? starlink第三代终端和第二代终端的额差异 阅读详情

相关推荐

深入MoveIt与OMPL集成开发:从源码编译到自定义规划算法实战

本文详细介绍了如何从源码编译集成MoveIt与OMPL,并实现自定义规划算法的完整流程。通过清理环境、获取源码、解决编译依赖与错误,最终指导开发者创建并集成名为MyRRT的自定义规划算法,从而实现对机器人运动规划栈的深度定制与优化。

h0i1j2k3l的博客 467

使用方法引用的使用场景--通过this来引用本类当中的成员方法

this指代当前对象,如果需要引用的方法就是本类当中的成员方法,那么可以使用***this::成员方法***格式来优化Lambda表达式 @FunctionlInterface public intterface Study { // 定义一个学习抽象方法 void study(); } // 定义一个学生类 public class Student { // 定义一个成员方法,方法的参数传递一个函数式接口Study public void study(Study s) { s.study();

czw的博客 554

从深算一号到三号:海光DCU的技术演进与国产超算突围之路

本文梳理了海光DCU从深算一号到三号的技术演进历程,展现了国产高性能计算芯片从填补空白到追赶并行的突围之路。文章重点分析了深算系列在性能提升、软件生态(DTK)建设及超算平台构建方面的关键进展,并探讨了其在AI大模型训练、科学计算等领域的应用实践与未来挑战。

ipfs8storage的博客 1059

AbstractMap详解

/ 包:java.util// 包:java.util package java . util;Map.Entry;​同 SimpleEntry 一样,都继承了 Map.Entry 和 序列化接口。

qq_43842093的博客 1410

TMS320F280039 CMD文件配置避坑指南:从.map文件看懂内存分配与溢出排查

本文详细解析了TMS320F280039芯片的CMD文件配置问题,通过.map文件分析内存分配与溢出排查。文章提供了实用的诊断技巧和解决方案,帮助开发者有效应对段溢出、地址重叠和栈堆冲突等常见问题,优化DSP程序的内存管理。

weixin_29168813的博客 441

汇丰外包Java岗面试复盘:Zoom面1.5小时,从英语、粤语到现场敲代码的极限挑战

本文详细记录了汇丰银行外包Java岗位的面试全过程,包括多语言切换(英语、粤语)的技术沟通挑战和现场编码测试的实战经验。从高并发编程到JVM调优,面试不仅考察技术深度,更注重实战问题解决能力。文章分享了应对跨国银行技术面试的实用策略,帮助Java开发者在跨文化环境中提升竞争力。

weixin_42524824的博客 361

Map之AbstractMap、HashMap

基于哈希表的Map接口实现。这个实现提供了所有可选的映射操作,**并允许空值和空键**。(HashMap类大致相当于Hashtable,不同之处在于它是不同步的,并且允许为空。)这个类不保证映射的顺序;特别是,它不能保证顺序在一段时间内保持不变。 该实现为基本操作(get和put)提供恒定时间的性能,前提是哈希函数将元素正确地分散到桶中。对集合视图进行迭代所需的时间与HashMap实例的“容量”(桶的数量)加上它的大小(键值映射的数量)成正比。因此,如果迭代性能很重要,那么不要将初始容量设置得太高(或负载

好看的皮囊千篇一律,有趣的灵魂万里挑一。 1378

告别混乱!在Unity中为Best MQTT v3设计清晰的服务层:配置、连接、订阅发布模块拆分指南

本文详细介绍了如何在Unity中使用Best MQTT v3插件构建清晰的服务层架构,包括配置管理、连接服务、订阅管理和发布服务的模块化拆分。通过解耦设计、事件驱动和接口抽象,提升代码可维护性和可测试性,适用于物联网和实时通信开发场景。

weixin_30576827的博客 357

Java集合类:AbstractMap

文章目录引言源码解析抽象函数entrySet()两个集合视图操作方法两个子类感谢参考: 引言 今天学习一个Java集合的一个抽象类 AbstractMap ,AbstractMap 是Map接口的 实现类之一,也是HashMap、TreeMap、ConcurrentHashMap 等的父类,它提供了Map 接口中方法的基本实现(关于Map接口有疑惑的同学可参考 Java根接口:Collectio...

1185

[调参神器]使用VOFA+上位机进行PID调参(附下位机代码)

​ 简单地来说,VOFA+是一个超级串口助手,除了可以实现一般串口助手的串口数据收发,它还可以实现数据绘图(包括直方图、FFT图),控件编辑,图像显示等功能。​ 如果只是想要用VOFA+来进行数据绘图,直接使用一个波形图控件就行,但是如果想要把VOFA+当作一个长期使用的调参助手,我们最好设置一下控件。VOFA+简洁好用,但是又有点太简洁了,部分体验并不是很好(比如不能调整控件大小,保存文件不太方便等),所以如果学有余力,推荐自己用QT/PyQT写上位机。接下来,我们要将指令中的数据提取出来。

qq_56089182的博客 4万+

工业以太网通讯Profinet协议详解

Profinet是通过西门子控制系统被广泛使用的工业通信协议,是一种较新的,基于以太网的工业通讯协议。

mydatai的专栏 8851

AbstractMap抽象类

JDK源码分析模板第1部分 AbstractMap介绍第2部分 AbstractMap数据结构第3部分 AbstractMap源码解析(基于JDK-8u201)内部类SimpleEntry内部类SimpleImmutableEntry 第1部分 AbstractMap介绍 AbstractMap简介 AbstractMap继承自Map接口,具有Map的所有方法,即针对K, V, Entry三种数据...

彬 414

手把手教你学simulink(11.6)--Simulink 航空航天场景:基于Simulink的飞机俯仰控制系统的数学模型

自动驾驶系统在航空航天领域具有重要应用,特别是在商业航空、军用航空和无人机等领域。PID控制器因其简单且有效的特性,被广泛应用于飞行控制。Simulink提供了一个强大的平台,用于建模、仿真和分析动态系统,非常适合设计和测试自动驾驶系统的控制器。通过本项目的实施,我们成功设计和仿真了一个用于控制飞机俯仰角的PID控制器。该项目展示了从系统建模、控制器设计、仿真验证到结果分析的完整流程,为PID控制器的设计提供了有价值的参考。希望这个实例能够为你的航空航天项目提供有用的指导。

MHD0815的博客 565

Java 集合体系之 AbstractMap 源码分析

AbstractMap 是一个实现了 Map 接口的抽象类,该类提供了 Map 接口的骨架实现,以最大限度的减少实现此接口所带来的工作量。

Airsaid 3245

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Java集合类Map之Map与AbstractMap

今日面试某著名公司,当问到java集合类

ximenchuiniu的专栏 1378

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Java源码分析 AbstractMap的keySet()方法

之所以我们需要实现的地方这么少,是因为AbstractXXX抽象类已经帮我们实现了许多方法,比如AbstractMap抽象类里面就已经实现了Map接口里的很多方法,同样,AbstractSet抽象类里面也已经实现了Set接口里的很多方法。

anlian523的博客 1189

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Java-AbstractMap

声明 1)该文章整理自网上的大牛和专家无私奉献的资料,具体引用的资料请看参考文献。 2)本文仅供学术交流,非商用。如果某部分不小心侵犯了大家的利益,还望海涵,并联系博主删除。 3)博主才疏学浅,文中如有不当之处,请各位指出,共同进步,谢谢。 4)此属于第一版本,若有错误,还需继续修正与增删。还望大家多多指点。大家都共享一点点,一起为祖国科研的推进添砖加瓦。 前言 AbstractMap抽象类实现了一些简单且通用的方法,本身并不难。但在这个抽象类中有两个方法非常值得关注,keySet和values方法源码的实

MasterPick的博客 242

java容器 抽象类AbstractMap源码分析

目录 简介 查询 size,isEmpty,containsKey,containsValue 增删改查 get,put,remove 批量操作 putAll,clear 两个字段 keySet,values keySet,values方法的内部类 通用方法 equals,hashCode,toString,clone,eq 内部类 SimpleEntry 内部类 Sim...

今天吃了吗的博客 287

JDK8中AbstractMap类源码分析

抽象类AbstractMap分析

iCoding91 369

jdk源码分析之AbstractMap

package java.util; import java.util.Map.Entry; //提供一个Map的框架,避免重复代码 //子类需要实现 //内部的非抽象方法都是在定义所有map都应该具有的性质 //子类如果需要改实现,需要override public abstract class AbstractMap implements Map { /** * So

garypotter的博客 365

Java源码阅读--AbstractMap

Java源码阅读–AbstractMap 结构 头: 属性: transient volatile Set<K> keySet; transient volatile Collection<V> values; SimpleEntry 先看一下“头” 实现了Entry,那来看看它的具体实现方法吧(过于简单的方法就不赘述了) 只有俩属性 private final K key; private V value;

qq_37695054的博客 342

java源码分析之集合框架AbstractMap 08

AbstractMap: 2.AbstractMap         AbstractMap继承了Map,但没有实现entrySet()方法(该方法还是abstract修饰),如果要继承AbstractMap,需要自己实现entrySet()方法。没有真正实现put(K key, V value)方法,这里“没有真正实现”的意思是,该方法在形式上已经

坚定目标,超越自我 1687

Java常用数据结构之Map-AbstractMap

前言 Map集合是用来存储&lt;Key, Value&gt;键值对数据的,是日常开发中使用最多的数据结构之一。Map集合相对List集合来说结构会稍微复杂一些,所以Map系列会分开写。本文主要分析AbstractMap。 类图 Map接口中定义了各种基本方法,而键值对数据实际是保存在Entry中的。AbstractMap类和AbstractList类一样,都是一种模板类,提供了Map的基本实现...

QiwooMobile的博客 265

我的jdk源码(九):AbstractMap Map家族的骨架实现类

一、概述 AbstractMap类是Map大家族中的骨架实现类,在接口与实现类之间构建了一层抽象,其目的是为了复用一些比较通用的函数以及方便扩展,为子类提供共用的方法模板。 二、源码分析 (1) 类的申明,源码如下: public abstract class AbstractMap<K,V> implements Map<K,V> AbstractMap类是一个抽象类,并且实现了Map。 (2) 成员变量,源码如下: //k...

Java觉浅的博客 400

Java集合源码分析(六)——ConcurrentHashMap

简介 ConcurrentHashMap 是一个线程安全的散列表,存储的内容是键值对映射。 ConcurrentHashMap 继承于AbstractMap,实现了ConcurrentMap、Serializable接口。 ConcurrentHashMap 存储的键值对是无序的。 源码分析 父类 AbstractMap 接口 ConcurrentMap Serializable 字段 // 数组最大容量 private static final int MAXIMUM_CAPACITY

Think Different. 284

HashMap源码分析(一)--AbstractMap以及Map分析

有图可以看出,HashMap继承了AbstractMap,接入了Cloneable接口,Map接口与Serializeble接口。当然排开Cloneable用于允许拷贝,Serializeble用于允许对象的序列化,所以不需要多家赘述。剩下的就只有AbstractMap类与Map接口的分析。 一、Map接口 由于源码比较零散,所以也不截图了 Map作为一个接口,仅仅是用于完成一些初始方法...

weixin_30847865的博客 183
上一篇: java集合类源码分析(五):Map接口
下一篇: Java集合类源码分析(七):HashMap&LinkedHashMap
不晓得X
博客等级 码龄10年 114粉丝 50原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值