我有一个正常运行的Groovy 2.4.3方法,我认为我可以使用collect()
闭包来实现 groovier ,但不完全确定如何:
List<Buzz> deriveBuzzesFromFizz(Fizz fizz) {
List<Buzz> buzzes = []
fizz.foobars?.each {
if(it.label.equals('whistlefeather')) {
buzzes << it
}
}
buzzes
}
也许是这样的:
List<Buzz> buzz = fizz.foobars?.collect {
it.label.equals('whistlefeather')
}
......或者附近?!
答案 0 :(得分:4)
你在想一个findAll
fizz.foobars?.findAll {
it.label == 'whistlefeather'
}