Reputation: 3330
I need example configuration to totally disable check-style for hashCode()
and equals()
methods.
Upvotes: 5
Views: 2434
Reputation: 23856
This is maybe not a direct answer to your question, but Lombok really shines on avoiding this sort of boilerplate code: http://projectlombok.org
For this case, you can just annotate your classes with:
@EqualsAndHashCode(of="id")
or
@EqualsAndHashCode(excludes={"these","fields","wont","be","compared"})
Haven't tested it against checkstyle, though...
Upvotes: 1
Reputation: 2260
Checkstyle in eclipse. Open Windows -> Preferences -> Checkstyle.
If you are using the default configuration, copy to a different name, select the copied one and click configure. Search for equals and select 'Equals and Hashcode' under coding problems. Uncheck all the enabled ones that you dont need.
Hit ok and set as default.
Upvotes: 2
Reputation: 61705
See EqualsHashCode in Checkstyle 5.5: Coding Config. Just remove the
<module name="EqualsHashCode"/>
from your checkstyle configuration file, or do it through the Eclipse plugin. But I would ask myself why you're doing this. Bad implementation of equals() and hashCode() is a common source of errors, so be very careful before you do this.
Upvotes: 3