Eclipse Tip: Generate hashCode and equals methods

Previously I had mentioned about generating getters and setters in Eclipse. Another set of methods which are commonly used (or not) are the ‘equals( Object obj )‘ and ‘hashCode()‘ methods. Eclipse can generate them for you.

Just right click on the editor and go to Source>Generate hashCode() and equals()… The above dialog pops up and lets you choose the fields you want to be included in these methods. Just select the ones you need and press OK. You now have the methods generated.

This is simple feature but is a time saver.