Coming from Java to Groovy and seeing that Groovy looks like Java with sugar, you are tempted to write code like this:
private String take(List list) {
return 'a list'
}
private String take(String s) {
return 'a string'
}
But when you call this method take with null you get strange results:
public void testDispatch() {
String s = null
assertEquals('a string', take(s)) // fails!
}
It fails because Groovy does not use the declared types. Since it is a dynamic typed language it uses the runtime type which is NullObject and calls the first found method!
So when using your old Java style to write code in Groovy beware that you are writing in a dynamic environment!
Lesson learned: learn the language, don’t assume it behaves in the same way like a language you know even when the syntax looks (almost) the same.