We've generated some (well a lot) of classes using HyperJAXB. All of the classes implement Equals and HashCode and have the implementation style below. Appears this code is never executed.. is there any particular reason we need this code? I'm looking to simplify the classes if we can.
public boolean equals(Object object) {
if (!(object instanceof MyClass)) {
return false;
}
if (this == object) {
return true;
}
final EqualsBuilder equalsBuilder = new JAXBEqualsBuilder();
equals(object, equalsBuilder);
return equalsBuilder.isEquals();
}
public void hashCode(HashCodeBuilder hashCodeBuilder) {
hashCodeBuilder.append(this.getValue());
hashCodeBuilder.append(this.getId());
}
public int hashCode() {
final HashCodeBuilder hashCodeBuilder = new JAXBHashCodeBuilder();
hashCode(hashCodeBuilder);
return hashCodeBuilder.toHashCode();
}
If your application or the JAXB infrastructure ever puts instances of those objects into collections or maps, then there is a good chance that the
equals
andhashCode
methods will be used.EDIT
I found the following in the hyperjaxb3 documentation:
So it should be possible to turn off generation of those methods, but the hyperjaxb3 designers seem to be saying that it is better not to.