1. 程式人生 > >Collection 源碼匯總

Collection 源碼匯總

bstr end interface pre 匯總 port trac 不可變類 exc

ConcurrentHashMap:

  public class ConcurrentHashMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>, Serializable{}

  public abstruct class AbstractMap<K,V> implements Map<K,V>{}

  public interface Map<K,V>{}

AbstractMap:

  AbstractMap提供了Map的基本實現,可以不從頭開始實現一個Map,只需按需求實現/重寫即可

  AbstractMap唯一的抽象方法:public abstract Set<Entry<K,V>> entrySet(); 這個Set不支持add和remove方法

  實現不可變類,只需繼承並實現setEntry方法

  實現可變類,還得重寫put方法,因為默認的put方法是:

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

    

  

Collection 源碼匯總