Groovy default params to avoid one-argument methods being called without params
In a language like Apache Groovy, when statically compiled, you’d get a compilation error if you forgot a parameter, because the signature couldn’t be found by the compiler. In dynamic mode, you’d get a runtime error though, with a MissingMethodException (and the error message should give you a hint as to which method you should actually call instead).
But there’s a particular case of the Groovy method dispatch that’s a bit special (and actually something we might be removing at some point in a breaking version of the language, but it’s been there since 1.0). When you have single-argument methods, you’re allowed to call those methods without passing a parameter! And the parameter is filled simply with null. So you might have made a mistake in your code, forgetting to pass an actual parameter value, but you’d get neither a compilation error nor a runtime exception, but a null value.
I’ve also pushed that example on the Groovy Web Console, if you wanna play with it.
Groovy Weekly #77
One API, many facades?