Welcome to the Joint-Venture Blog from Fabio Cortesi and Stefan Jäger.
04.06.2008 - Stefan Jäger
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…
03.06.2008 - Stefan Jäger
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