The contract of equals with regards to null
, is as follows:
For any non-null reference value
x
,x.equals(null)
sho
Personally, I'd rather it perform as it does.
The NullPointerException
identifies that the problem is in the object against which the equals operation is being performed.
If the NullPointerException
was used as you suggest and you tried the (sort of pointless) operation of...
o1.equals(o1)
where o1= null...
Is the NullPointerException
thrown because your comparison function is screwed or because o1 is null but you didn't realise?
An extreme example, I know, but with current behaviour I feel you can tell easily where the problem lies.