【发布时间】:2012-09-23 13:02:18
【问题描述】:
在工作中,我们正在讨论一个简单(或不那么简单)的问题。 ¿ 下面的调用方法有区别吗?
class Obj {
def num
def prtn = {
print this.num
}
}
def listObj = [new Obj(num:1), new Obj(num:2), new Obj(num:3), new Obj(num:4)]
// End Common code
// Method #1
def lst = listObj.collect{ obj-> obj.prtn() }
// Method #2
def lst = listObj.collect{ obj-> { -> obj.prtn()} }.each{ it() }
// Common code
【问题讨论】:
标签: collections groovy closures