him_aeng (1) [Avatar] Offline
#1
...
def picture = new Drawing(shapes:
[new Square(width:1), new Circle(radius:1)])
...

Would you please tell me about the meaning of code "shapes: [new Square(width:1), new Circle(radius:1)])" I don't understand the ":" operator?

Best Regards
Tanakorn Numrubporn
Mittie (397) [Avatar] Offline
#2
Re: Meaning of Listing 5.10
Hi Tanakom,

in new MyClass(a:b) the a:b defines a map that is sent to the constructor of MyClass. In that map there will be an entry with key 'a' and value b. When sent to a constructor, this map will be used to set the 'a' property of myClass to the b value.
In your example, the b value is a list, literally declared in [ ] brackets. The list items are themselves objects, created through their constructor, which again uses the map notation to set the values of the width and radius properties.
For more details on ':' refer to the section about maps.
For more details on the use of maps in constructors, refer to the GroovyBeans section.

thanks for posting and keep groovin'
Dierk