The following code will produce an assertion error
def foo(a,b,c='awesome',d=null) {
assert d
}
foo(1,2,d='bar')
Why does it give an error? Why is the keyword assignment of d not working? I find this very different from Python keyword argument.
Groovy doesn’t do keyword arguments quite the same as python.
First, the syntax is map-like. Instead of
you need
Second, groovy can’t map the arguments to keywords by name. A way to accomplish this in groovy is to accept the keyword arguments as a map:
More details on how groovy handles this is here: http://groovy.codehaus.org/Extended+Guide+to+Method+Signatures.