Hi Jerome,

I saw the implementation of equals for cookie and have to admit I was
almost shocked :)

The code brings out to the fore the following phrases/sentences from
the Object#equals and hashcode contracts

Object#equals
1.1 equals method for class Object implements the most discriminating
possible equivalence relation on objects

1.2 so as to maintain the general contract for the hashCode method,
which states that equal objects must have equal hash codes.

Object#hashCode

2.1 It is not required that if two objects are unequal according to
the equals(java.lang.Object) method, then calling the hashCode method
on each of the two objects must produce distinct integer results


the essence of my objection to the present implementation is that
"equal objects must have equal hash codes" but not "objects having
equal hashCodes must be equal"

In cookies case an example might be contrivied where for one cookie
the version is say 1, name evaluates to 2 and all others evaluate to 1
and for another cookie the version is 2, name evaluates to 1 as do the
other params .. in this case equals as implemented by Cookie will lead
to a faulty conclusion of "true". The equals has to be even more
discriminating  than hashCode. and the instanceOf doesn't make it
discriminating enough.

I hope I was succint enough.

Cheers
Piyush

Reply via email to