我们是否需要 HyperJAXB 生成 hashCode 和 hashCode?等于方法吗?
我们使用 HyperJAXB 生成了一些(很多)类。所有类都实现 Equals 和 HashCode,并具有以下实现风格。看来这段代码从未被执行过。我们需要这段代码有什么特殊原因吗?如果可以的话,我希望简化课程。
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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的应用程序或 JAXB 基础设施曾经将这些对象的实例放入集合或映射中,那么
equals
和hashCode
方法很可能 被使用。编辑
我在hyperjaxb3文档:
因此应该可以关闭这些方法的生成,但 hyperjaxb3 设计者似乎说最好不要这样做。
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.
可以在 maven-hyperjaxb3-plugin 配置中使用
如果您想禁用 equals/hashCode 方法生成, 。不过我不会推荐这样做。
此致,“hyperjaxb3 设计师”。 :)
You can use
in your maven-hyperjaxb3-plugin configuration if you want to disable equals/hashCode methods generation. However I won't recommend to.
Sincerely yours, "hyperjaxb3 designers". :)