Shorthand way for assigning object properties in Groovy?

后端 未结 3 1532
轻奢々
轻奢々 2021-02-12 16:09

I create Groovy objects using this convention...

Item item1 = new Item( name: \"foo\", weight: \"150\")

...is there a shorthand convention for

3条回答
  •  萌比男神i
    2021-02-12 16:36

    You have the with method, as described by the great Mr Haki

    item1.with{
        name = "hello"
        weight = "175"
    }
    

提交回复
热议问题