这儿有个好例子:
传布操纵符(spreadoperator):*
在Java中,要想遍历一组人并搜集人名。我大概得如许写:用Groovy,我会这么写:复制代码
- Listnames=newArrayList();for(Iteratoriterator=people.iterator();iterator.hasNext();){Personperson=(Person)iterator.next();names.add(person.getName());}System.out.println(names);
呵呵,复杂吧。我还能够如许写:复制代码
- defnames=people*.nameprintlnnames
复制代码
- defnames=people.collect{it.name}printlnnames
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |