The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 You Are What You Is: Defining Object Identity
Subject:  If you run into this, your program is broken
Date:  2006-07-27 09:32:05
From:  mernst


"equals-but-no-hash" and "rehash" are gross hacks and should not be taken seriously. For me, the underlying pattern to follow is: "Define (maybe context-dependent) the point in an object's lifetime, after which it is illegal to alter those fields that make up the object's "value-identity" (as implemented by #equals/#hashcode). At that point your object has "settled" on its identity. Only after this point, it's ok to put this object into a hash structure."

A software that violates this rule is not sound. It's not just about hashing. The semantics are broken. The above definition gives you a number of interpretations about the when's, how's and who's of enforcing it.


 Feed java.net RSS Feeds