微信公众号:爱问CTO
专业编程问答社区
www.askcto.com
从 JDK 文档中,我们可以看到当时作者的想法。
This class implements a hash table, which maps keys to values. Any non-null object can be used as a key or as a value
To successfully store and retrieve objects from a hashtable, the objects used as keys must implement the hashCode method and the equals method
可以看出,当时不允许是因为希望每个 key 都会实现 hashCode 和 equals 方法。而 null 显然没有。由于null不是对象,因此不能在其上调用.equals()或.hashCode(),因此Hashtable无法将其计算哈希值以用作键。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。