【发布时间】:2012-10-10 22:06:34
【问题描述】:
在Java API中,HashSet的实现是使用一个Object作为内部HashMap的值,
// Dummy value to associate with an Object in the backing Map
private static final Object PRESENT = new Object();
public boolean add(E e) {
return map.put(e, PRESENT)==null;
}
但是HashMap允许它的值为null。我认为这不是填充值所必需的,那为什么需要呢?
【问题讨论】: