Groovy和Scala的闭包回调写法
Groovy:
定义函数,入参为闭包变量
public void test(Closure closure) {
closure.call(1);
}
函数调用
test { x -> println x + 1 }
Scala:
定义函数,入参为闭包、函数变量
def test[U](f: (Int) => U): Unit = {
f.apply(1)
}
函数调用
test((x: Int) => println(x + 1))