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