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

Annotation to override equals/hashCode in all implementations? #14

Open
GoogleCodeExporter opened this issue Apr 22, 2015 · 2 comments
Open

Comments

@GoogleCodeExporter
Copy link

Will be an annotation to suggest implementation of equals/hashCode in all
implementations of an interface (all subclasses of a class, including itself)?
It might be useful to reduce error caused by using the default
implementation of equals/hashCode methods.

(I am not sure whether it is useful to have an annotation only for concrete
implementations, and one another requiring them on both abstract and
concrete implementations too.)

Is might be also useful similar to toString methods.

Original issue reported on code.google.com by aborgabor on 23 Jun 2009 at 1:39

@GoogleCodeExporter
Copy link
Author

It is very easy - declare equals/hashCode/toString in your interface, or if you 
have
a class - override Object's ones with abstract. Children will either declare 
your
methods, or won't compile.

Original comment by [email protected] on 19 Oct 2009 at 11:19

@GoogleCodeExporter
Copy link
Author

earwin, I think the solution you mentioned with interfaces does not work with
eclipse's 1.6 compiler, and declaring the hashCode, equals (toString) methods as
abstract will require to have helper methods to access the state of the base 
classes
in descendents, or an alternative implementation of hashCode, equals (toString)
accessible to descendent classes.

Original comment by aborgabor on 19 Oct 2009 at 11:45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant