The classes EqualsBuilder and HashCodeBuilder from the Apache Commons Lang library can be used for object comparison purposes.
E.g., one can test equality between two Person
objects like follows:
Person p1 =...;
Person p2 =...;
boolean equals = new EqualsBuilder().
append(p1.name, p2.name).
append(p1.secondname, p2.secondname).
append(p1.surname, p2.surname).
append(p1.age, p2.age).
isEquals();
Suppose that a field is not mandatory, e.g. secondname
. How does EqualsBuilder and HasCodeBuilder handle this fact? Is the comparison done on this field or not? Or the comparison on a null field can be skipped as a special option?