Often time methods take more than 3 parameters which are all of the same type, eg.
void mymethod (String param1, String param2, String param3)
then it's very easy for the client to mix up the parameters orders, for instance inverting param1 and param2:
mymethod (param2, param1, param3);
...which can be the cause of much time spent debugging what should be a trivial matter. Any tips on how to avoid this sort of mistake (apart from unit tests) ?
You are searching for: Named Parameter idiom in java
Use javadoc, it is your friend.
With any good IDE, doing mouse-over the name of the method should give you a tool tip window with useful information.
I know that with Eclipse, if your javadoc makes use of the @param tag, your chances for confusing which parameter is which will go down greatly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With