Recipes to @Override “equals” and “hashCode” methods

equals

@Override 
public boolean equals(Object o) {

    if (o == this) return true;

    if (!(o instanceof MyObject)) return false;

    MyObject mo = (MyObject)o;

    return mo.mostImportantField == mostImportantField 
        && mo.sencondField == sencondField
        && mo.lessImportantField == lessImportantField;
}

hashCode

@Override
public int hashCode() {
    int result = Integer.hashCode(firstField);
    result += 31 * result + sencondField.hashCode(); 
    result += 31 * result + Integer.hashCode(thirdField); 
    return result;
}

Additional considerations