Not a direct answer to the question, however below would be a time saver during initial development:
Disclaimer: Apache Commons library is used.
- Add a new Eclipse template called
xreflect
in Java > Editor > Templates
; Add below into its pattern textarea:
// ---------- template start ----------- //
${:import(org.apache.commons.lang.builder.EqualsBuilder,org.apache.commons.lang.builder.HashCodeBuilder,org.apache.commons.lang.builder.ReflectionToStringBuilder)}
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(
final Object pObj) {
return EqualsBuilder.reflectionEquals(this, pObj);
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
// ---------- template end ----------- //
- Give
OK
, OK
- Just go to the end of a Java class, type
xreflect
and press Ctrl + Space to autofill equals(), toString() and hashCode() methods automatically.