Andrey Hihlovskiy
Professional blog on groovy, gradle, Java, Javascript and other stuff.
Fun with groovy maps and function call syntax
August 1, 2013
Posted by on A function having a Map as first parameter:
void doIt(Map attrs, Object content) { println attrs println content }
supports equally valid call syntax variations:
// "classical" call syntax, known from java world doIt([color: 'red', type: 'fruit'], 'hello!') // parentheses can be omitted doIt [color: 'red', type: 'fruit'], 'hello!' // even square brackets for map can be omitted doIt color: 'red', type: 'fruit', 'hello!' // order of map properties does not matter, // map properties can be intermixed with unnamed parameters. doIt color: 'red', 'hello!', type: 'fruit' doIt 'hello!', type: 'fruit', color: 'red'
this effectively allows to implement named parameters in groovy.
Recent Comments