On Mar 28, 2005, at 12:12 PM, Carsten Ziegeler wrote:

Glen Ezkovich wrote:
On Mar 28, 2005, at 6:35 AM, Carsten Ziegeler wrote:


I'm sure you are aware of this and take this as you will, the general
contract for hashCode states that
"If two objects are equal according to the equals(Object) method, then
calling the hashCode method on each of the two objects must produce the
same integer result."


So 2 distinct objects may have the same hashCode and it may be
necessary to bind 2 equal objects.

Yes, that's true - but I - in the role of the application developer -
know how hashCode works for my own objects. And from the JavaDocs for
Object:
"As much as is reasonably practical, the hashCode method defined by
class Object does return distinct integers for distinct objects."

So unless you have overwritten hashCode everything is fine.

Exactly. If I override equals, I override hashCode and I override equals for just about any class I would use to bind. (its a habit... what can I say)



Now, I don't want that the repeater always relies on hashCode but perhaps as a default - if no identity is given for example. And everything else stays the same.

I can live with this but the documentation needs to be very explicit with this. It seems like an error waiting to happen. Sylvain's solution seems safer.



Glen Ezkovich HardBop Consulting glen at hard-bop.com



A Proverb for Paranoids:
"If they can get you asking the wrong questions, they don't have to worry about answers."
- Thomas Pynchon Gravity's Rainbow




Reply via email to