Say, I have the following class,
class Some implements Comparable<Some> {
@Override
public int compareTo(Some o) {
Objects.requireNonNull(o, "o is null");
// Let's just compare this.other and o.other.
// What should I do when this.other is null?
return this.other.compareTo(o.other);
}
private Other other;
}
I just want to compare the this.other
and o.other
.
What should I do(throw) when this.other
is null
? Just NullPointerException
or IllegalStateException
?