Hashtable源码 key value是否为null

在看Hashtable源码 其中
[code="java"]

public synchronized V put(K key, V value) {
// Make sure the value is not null
if (value == null) {
throw new NullPointerException();
}

// Makes sure the key is not already in the hashtable.
Entry tab[] = table;
int hash = key.hashCode(); 
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) {
    if ((e.hash == hash) && e.key.equals(key)) {
    V old = e.value;
    e.value = value;
    return old;
    }
}

modCount++;
if (count >= threshold) {
    // Rehash the table if the threshold is exceeded
    rehash();

        tab = table;
        index = (hash & 0x7FFFFFFF) % tab.length;
}

// Creates the new entry.
Entry<K,V> e = tab[index];
tab[index] = new Entry<K,V>(hash, key, value, e);
count++;
return null;
}

[/code]
代码第10行 [color=red]如果key为空这里会nullPointer...为什么不像value一样判断下 再抛异常呢[/color]
看的比较浅 请问Hashtable key/value不能为null还有其他因素么?谢谢了

NullPointerException属于RuntimeException

一般应由JVM抛出

这里只是手动抛出

lz可以这么理解:
因为put方法中的代码 没有调用value的引用(不像key,需要调用key.hashCode())
因此不会由JVM自动抛出
不得已在方法开始的地方对value进行了手动check

这只是JDK的规范 没听说过为什么要这么做~