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

Example implementations for hashCode() in documentation #1896

Open
offbynull opened this issue Mar 7, 2022 · 0 comments
Open

Example implementations for hashCode() in documentation #1896

offbynull opened this issue Mar 7, 2022 · 0 comments

Comments

@offbynull
Copy link

offbynull commented Mar 7, 2022

What happened

While documentation does exist that explains hashCode(), that documentation is lacking and doesn't provide many (any?) implementation examples. It would nice for users to...

  1. see a hashCode() implementation example.
  2. be provided with a quick list of best practices.
  3. be provided with a quick overview of how hash() works.

The implementation example could be as simple as just calling into hash() several times and mixing the results:

return Immutable.hash(this.numeric_field) ^ Immutable.hash(this.string_field) ^ Immutable.hash(this.boolean_field));

How to reproduce

Go ask a person unfamiliar with hashCode()/equals() to read the documentation and attempt an implementation for some custom object.

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

No branches or pull requests

1 participant