I have a groovy DSL script like this:
entity(attribute1:"one", attribute2:"two")
so far so good. I run the script and set the script’s delegate to a class where entity’s defined, and the class handles everything.
Now I want to do this:
entity(attibute1:(subattribute1:"one", subattribute2:"two"))
Is this somehow syntactically possible? Since (subattribute1:”one”, subattribute2:”two”) itself doesn’t mean anything, I’m assuming not, though I’m wondering if there are some Groovy magic that I’m not aware of that allows this.
And I don’t want to do
entity(attibute1:[subattribute1:"one", subattribute2:"two"])
even though I know that works. Just a syntax preference.
No, you have to use the square brace (as you have said you don’t want).
The first example:
is a shortcut for actually calling:
So, you would either need the square braces, (to signify the
attribute1key contains a map, or you would need to prefix the brace with another method name such as: