开发者

How does this work? Groovy Map creation with nested closures.

I'm rather new to Groovy, and recently created a canned message using a Map for testi开发者_如何学Cng. I created it using closures (not fully understanding, that's what I did, and changed it to the standard Map notation). Now I want to understand why the closure notation worked.

So the following two Maps get created properly. My question is how is Groovy interpreting the nested closures into a map?

Map notation:

Map m = [
  person : [
    first : "Flo",
    middle : "Over",
    last : "Stack"
  ],
  address : [
    street1 : "123 Any Street",
    street2 : "2nd Floor",
    city : "Anytown",
    state : "YR",
    zip : "99999"
  ]
]

Closure Notation:

Map m = {
  person {
    first "Flo"
    middle "Over"
    last "Stack"
  }
  address {
    street1 "123 Any Street"
    street2 "2nd Floor"
    city "Anytown"
    state "YR"
    zip "99999"
  }
}


Groovy has a special concept for creating tree structures called Builder. You can find more infos here: http://groovy.codehaus.org/Builders

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜