?本次分析代码为JDK1.8中HashTable代码。
??HashTable不允许null作为key和value。
??HashTable中的方法为同步的,所以HashTable是线程安全的。
Entry类
介绍
Entry是HashTable内的一个静态内部类,实现了Map.Entry接口。table的类型就是Entry。
基本参数
hash:存这个Entry的hash值
key:存key值
value:存value的值
next:通过链表连接下一个Entry
final int hash;final K key; V value; Entry<K,V> next;
构造函数
用来新建Entry,需要四个参数。
protected Entry(int hash, K key, V value, Entry<K,V> next) { this.hash = hash; this.key = key; this.value = value; this.next = next;
}方法
getKey方法:返回key值
getValue方法:返回value的值
setValue方法:修改value值
重写了equals和hashCode方法:hashCode方法通过计算该Entry的hash值与value的hash值进行异或运算;equals方法通过判断key和value是否同时相同来判断。
网友评论

