Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

override hashcode() #707

Closed
wants to merge 6 commits into from
Closed

override hashcode() #707

wants to merge 6 commits into from

Conversation

yinlinchen
Copy link
Contributor

When override equal(), should override hashcode()

@awoods
Copy link

awoods commented Feb 10, 2015

Please add a test that demonstrates the "why" of adding the hashCode() method.

@yinlinchen
Copy link
Contributor Author

According to the Java Language Specification, there is a contract between equals(Object) and hashCode():

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. 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. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. 

In order to comply with this contract, those methods should be either both inherited, or both overridden.

@awoods
Copy link

awoods commented Feb 10, 2015

Every functional update should be accompanied by one or more unit and integration tests.
Please add a test that demonstrates the "why" of adding the hashCode() method.

@yinlinchen
Copy link
Contributor Author

will add testHashCode()

On Tue, Feb 10, 2015 at 10:15 AM, Andrew Woods notifications@github.com
wrote:

Every functional update should be accompanied by one or more unit and
integration tests.
Please add a test that demonstrates the "why" of adding the hashCode()
method.


Reply to this email directly or view it on GitHub
#707 (comment).

@awoods
Copy link

awoods commented Feb 19, 2015

Resolved with: c2e1af0

@awoods awoods closed this Feb 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants