-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix noisy hashCode/equals implementations for Family
Signed-off-by: Anton Gustafsson <antag99@gmail.com>
- Loading branch information
Anton Gustafsson
committed
May 15, 2015
1 parent
db1286f
commit b01cb15
Showing
1 changed file
with
2 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b01cb15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since family isn't used as a key in the map, you can remove both this overrides at all
b01cb15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Family
is used as key inEngine
. Theequals()
implementation could indeed be removed, but that is not an improvement.b01cb15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to say that
equals()
should compare indices for security reasons, although there should never be an instance ofFamily
with different ref value and same index.Wherever you override hashCode you should always override equals and viceversa.
b01cb15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArtCraft could you make
equals()
compare indices? Theoretically, this class doesn't abide by the equals/hasCode contracts as you left it.Are tests passing?
b01cb15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't break the contract, as
hashCode()
does not return different integers whenequals()
returns true.