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

equalsHelper #2521

Closed
vorburger opened this issue Jul 8, 2016 · 3 comments
Closed

equalsHelper #2521

vorburger opened this issue Jul 8, 2016 · 3 comments

Comments

@vorburger
Copy link
Member

Hello, how do you guys like an idea for an equalsHelper, which can be used like this ?

The point would just be to avoid repeating the well known null/this/getClass() in every equals() - less litany, more readable code, less accidental bugs.

Just a thought, interested to hear if you think this is cool (and could be something for Guava).

@lowasser
Copy link
Contributor

lowasser commented Jul 8, 2016

Are you familiar with AutoValue? (https://github.com/google/auto/blob/master/value/userguide/index.md)

AutoValue is our current preferred approach for dealing with the pain of equals/hashCode/toString in Java value classes.

@ogregoire
Copy link

AutoValue has the big disadvantage of not being compatible with major ORM frameworks, for instance. While an approach like the one suggested is.

@vorburger
Copy link
Member Author

vorburger commented Jul 9, 2016

@lowasser yep I've seen AutoValue (but never actually tried it) - certainly like the approach a lot in general (personally I'd Code Generate my grandmother, if she was alive..), and do realize/just (re)learnt the PITA of hand-writing hashCode and equals (arrays, urgh! see https://git.opendaylight.org/gerrit/#/c/41600/), but there probably still are some cases when people hand-write equals? For those, perhaps this could be handy.

BTW: Perhaps you'd like to point to AutoValue more prominently from the main Wiki page about this where everyone looks at, on https://github.com/google/guava/wiki/CommonObjectUtilitiesExplained ?

PS: The trouble with tribbles, erm AutoValue, is applying it to (badly written..) existing "beans" used in a code base imposes changes e.g. from constructor to builder or factory - that's not always easily possible.

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

4 participants