鉴于:
class FruitBasket {
int apples = 0
int oranges = 0
}
我需要从每个 FruitBasket 中挑选出苹果。需要在processFruit中完成的工作:
def processFruit(list, picker) {
list.each {
println "processing " + picker(it)
}
}
def processAll() {
List fruitList = [
new FruitBasket("apples": 2, "oranges": 4),
new FruitBasket("apples": 3, "oranges": 5)
]
processFruit(fruitList, applePicker)
}
def applePicker(FruitBasket f) {
return f.getApples()
}
但它在抱怨@runtime
No such property: applePicker for class: FooTest
可能是关闭 FruitBasket arg 的问题......