class Vector { double x double y } def points = [ new Vector(x: 10, y: -5), new Vector(x: -17.5, y: 3), new Vector(x: -3.3, y: -1) ] assert points*.x == [10, -17.5, -3.3]
注意:*是可选的。我们也可以像下面这样写上面的语句,Groovy编译器对此仍然很满意。
assertpoints.x== [10, -17.5, -3.3]