Hashcode, equals and toString
equals
JDK
public final boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Employee other = (Employee) obj;
return Objects.equals(id, other.id)
&& Objects.equals(name, other.name);
}
Apache Commons
public final boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj, false);
}
hashCode
JDK
public final int hashCode() {
return Objects.hash(id, supportId);
}
Apache Commons
public final int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
toString
JDK
public final String toString() {
return new StringJoiner(" | ",
this.getClass().getSimpleName() + "[ ", " ]")
.add("name=" + name).toString();
}
Guava
public final String toString() {
return MoreObjects.toStringHelper(this)add("name", name).toString();
}
Apache Commons
public final String toString() {
return ToStringBuilder.reflectionToString(this);
}
public final String toString() {
return new ToStringBuilder(this).append("name", name).toString();
}
Last updated
Was this helpful?