Eclipse can generate hashCode and equals methods

By Alvin J. Alexander, devdaily.com

A nice feature of Eclipse is that you can easily generate hashCode and equals methods using the editor. This comes in handy when you're doing anything related to sorting, comparisons, comparators, etc.

To generate hashCode and equals methods, just have the desired Java class open in the Eclipse editor, then click the Source menu, then choose the "Generate hashCode() and equals()" menu item. Assuming you have class variables available, Eclipse will generate the methods for you. (Of course, like any generated code you'll want to review it, but I've been able to use the generated code in several tests so far.)


devdaily logo