wenwenlin / jsr-305

Automatically exported from code.google.com/p/jsr-305
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
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 earwin@gmail.com on 19 Oct 2009 at 11:19

GoogleCodeExporter commented 9 years ago
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