Welcome to this Blog. I am Software Engineer and work for Zühlke Engineering AG in Bern. This is my private blog, in which I will post mainly about technical stuff like Software Engineering or IT related topics. The views expressed herein do not necessarily represent those of my employer.
If you press CTRL + O in Eclipse, a list with all members and methods shows up. Red highlighted are private members/methods, green public ones. But unfortunately, inherited methods are invisible.
Now, just press CTRL + O again and you can see all inherited methods.
I know, the hint is mentioned in the bottom right corner, but I didn’t noticed this until today…
How many times in your lifetime have you overwritten the functions equals(), hashCode() or toString()? I did many times…
The Apache Commons Lang Package offers three basic classes for building the equals(), hashCode() or toString() method.
- EqualsBuilder
JavaDoc of the EqualsBuilder
All available fields can be append to the EqualsBuilder, which checks, if two objects are equals. It works with all primitive datatypes and objects (if they have implemented the equals method, of course).
- HashCodeBuilder
JavaDoc of the HashCodeBuilder
If you overwrite the equals() method, you also have to overwrite the hashCode() method. This builder has almost the same methods like the EqualsBuilder, but you should define two randomly chosen odd numbers in the constructor. Ideally the numbers are unique over all classes in the program.
- ToStringBuilder
JavaDoc of the ToStringBuilder
Appends all the desired members and prints something likePerson@7f54[name=Stephen,age=29,smoker=false]
« Newer Posts
