Why does SetN.contains not allow null arguments?
Line in reference: https://github.com/openjdk/jdk/blob/ec0618742ff6cfd6d83f1278e8d245673fb9ef2c/src/java.base/share/classes/java/util/ImmutableCollections.java#L946
@Override
public boolean contains(Object o) {
Objects.requireNonNull(o); <- Why is this here?
return size > 0 && probe(o) >= 0;
}
This means one cannot accept any Set object (that they have no control over) and simply use .contains(null) to check whether the set contains a null value. There are Sets that can contain null values, so this is a legitimate check.