That is correct. In Groovy, all map entries in a method call will be collected and passed in as the first parameter. In a methodMissing
, they are passed as the first element in the arguments array:
def methodMissing(String name, args) {
"$name ${args[0]} ${args[1]}"
}
assert foo(a: 1, 'john doe', b: 2) == "foo [a:1, b:2] john doe"
For a non-missing method call:
def method(map, name) { "$map $name" }
assert method(a: 1, 'test', b: 2) == "[a:1, b:2] test"
You can force the map normal order if you declare it using square brackets:
def methodMissing(String method, args) {
"$method ${args[0]} ${args[1]}"
}
assert echo("foo", [a: 1, b: 2]) == "echo foo [a:1, b:2]"
http://mrhaki.blogspot.com.br/2009/09/groovy-goodness-named-parameters-are.html