Home Fabio Cortesi Stefan Jäger

Welcome to the Joint-Venture Blog from Fabio Cortesi and 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.

image

Now, just press CTRL + O again and you can see all inherited methods.

image

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.

  1. 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).
     
  2. 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.
     
  3. ToStringBuilder
    JavaDoc of the ToStringBuilder
    Appends all the desired members and prints something like Person@7f54[name=Stephen,age=29,smoker=false]

 

 

 

« Newer Posts