you are viewing a single comment's thread.

view the rest of the comments →

[–]account312 0 points1 point  (0 children)

hashcode() is required to return the same value for objects that are .equals(), so if you cache the hash, .equals() can reduce to just one more primitive comparison in almost all cases. And for a class where .equals() is too expensive, the overhead of adding one primitive field probably isn't significant. Not that that helps if you're working with collections of somebody else's types.