In the Java API, the implementation of HashSet is using an Object as a value for the inside 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;
}
but HashMap allows its value is null. I think that's not necessary to fill the value, so why is this needed?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…