1.Spreading Operator:扩展操作符 *
class Car{ String make String model } def cars = [ new Car(make:'BenChi',model:'101'), new Car(make:'BaoMa', model:'102'),
null
] def makes = cars*.make println makes /*Output ['BenChi', 'BaoMa', null] */
2扩展操作符 *可以使用在任何实现了Iterable的类中
class Component{ Long id String name } class CompositeObject implements Iterable<Component>{ def components = [ new Component(id:1, name:'Foo'), new Component(id:2, name:'Bar') ] @Override Iterator<Component> iterator(){ components.iterator() } } def composite = new CompositeObject() println composite*.id println composite*.name /*Output [1, 2] [Foo, Bar] */