It is recommended and sometimes necessary, classes that represent values (value classes) to override hashCode()
, equals()
[and optionally
In the eclipse preferences (Window>Preferences) go to Java > Editor > Templates.
In there you can create a teplate with name:hashcode context:java description:Create a hashcode method. The Pattern should contain something like this:
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
Save and return to your java class. Type the name (hashcode) and press ctrl enter. You can then select your template from the drop down list.
Do the same for each method you want. You could also create a template that combines everything together as well.