Note that while method overloading is useful in cases where the methods do the same thing behind the scenes, it can become hell when this is not the case:
someObject.setValue(obj.getTime()); // getTime returns a java.util.Date
After some refactoring (Date changed to a long timestamp...):
someObject.setValue(obj.getTime()); // getTime now returns a long
In the new code setValue
may not behave like the previous one if a long is not handled like a java.util.Date
behind the scenes.
The compiler will not show any errors as another method with the same name will silently take over for your new type and the program will be broken !
Only use overloading if methods do the same thing, otherwise use a different method name each time to avoid issues with refactoring.