-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
Comments
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. |
AutoValue has the big disadvantage of not being compatible with major ORM frameworks, for instance. While an approach like the one suggested is. |
@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. |
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).
The text was updated successfully, but these errors were encountered: