java 中 Map 内部是怎么实现的
2个回答
展开全部
Map只是一个接口,只定义了具体的方法,没有去实现任何功能的
Map的源码如下:
public abstract interface Map<K, V>
{
public abstract int size();
public abstract boolean isEmpty();
public abstract boolean containsKey(Object paramObject);
public abstract boolean containsValue(Object paramObject);
public abstract V get(Object paramObject);
public abstract V put(K paramK, V paramV);
public abstract V remove(Object paramObject);
public abstract void putAll(Map<? extends K, ? extends V> paramMap);
public abstract void clear();
public abstract Set<K> keySet();
public abstract Collection<V> values();
public abstract Set<Entry<K, V>> entrySet();
public abstract boolean equals(Object paramObject);
public abstract int hashCode();
public static abstract interface Entry<K, V>
{
public abstract K getKey();
public abstract V getValue();
public abstract V setValue(V paramV);
public abstract boolean equals(Object paramObject);
public abstract int hashCode();
}
}
Map的源码如下:
public abstract interface Map<K, V>
{
public abstract int size();
public abstract boolean isEmpty();
public abstract boolean containsKey(Object paramObject);
public abstract boolean containsValue(Object paramObject);
public abstract V get(Object paramObject);
public abstract V put(K paramK, V paramV);
public abstract V remove(Object paramObject);
public abstract void putAll(Map<? extends K, ? extends V> paramMap);
public abstract void clear();
public abstract Set<K> keySet();
public abstract Collection<V> values();
public abstract Set<Entry<K, V>> entrySet();
public abstract boolean equals(Object paramObject);
public abstract int hashCode();
public static abstract interface Entry<K, V>
{
public abstract K getKey();
public abstract V getValue();
public abstract V setValue(V paramV);
public abstract boolean equals(Object paramObject);
public abstract int hashCode();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询