0
在循环中我创建了4封,并将它们添加到列表的打印内容:迭代和Groovy闭
closureList = []
for (int i=0; i<4; i++) {
def cl = {
def A=i;
}
closureList.add(cl)
}
closureList.each() {print it.call()println "";};
这将导致以下的输出:
4
4
4
4
不过,我本来期望代替0,1,2,3。为什么4次关闭对A有相同的值?