在Groovy中,如何从以下内容中提取新的列表:
def people = [ new Person(name:"Tom",yearOfBirth:1985),new Person(name:"Abigail",yearOfBirth:1987),new Person(name:"Joyce",yearOfBirth:1984),new Person(name:"James",new Person(name:"Scott",new Person(name:"Ruth",yearOfBirth:1984) ] class Person { String name int yearOfBirth }
以便新的列表如下所示:
["Tom","Abigail","Joyce","James","Scott","Ruth"]
解决方法
你可以做:
def names = people.name