That's a clash of concerns - equals is specced to never throw. And removing that now is an issue. But yes, that was a mistake too. It's not the only aspect of java that is a mistake, but fixing it in a backwards compatible way would be a cure that is worse than the disease so it isn't done.
Objects.equals is pointless if 'null should throw' is the mindset. Just call a.equals(b) instead of Objects.equals(a, b) then.
At best a sane equals can be written that does a.equals(b) if both are non-null and throws NPE if either (or both) are, but, 'make a utility method' is a shitty solution to these problems.
View all comments
Show parent comment
0
u/rzwitserloot Feb 21 '26
That's a clash of concerns -
equalsis specced to never throw. And removing that now is an issue. But yes, that was a mistake too. It's not the only aspect of java that is a mistake, but fixing it in a backwards compatible way would be a cure that is worse than the disease so it isn't done.Objects.equalsis pointless if 'null should throw' is the mindset. Just calla.equals(b)instead ofObjects.equals(a, b)then.At best a sane equals can be written that does
a.equals(b)if both are non-null and throws NPE if either (or both) are, but, 'make a utility method' is a shitty solution to these problems.