GROOVY 闭包
https://www.w3cschool.cn/groovy/groovy_closures.html
class Example{
def static Display(clo){
clo.call("Inner");
}
static void main(String[] args){
// def clos = {print "Hello World!"};
// clos.call();
// def clos = {param ->println "Hello ${param}"};
// clos.call("world!");
// def clos = {println "hello ${it}"};
// clos.call("world!");
// def str1 = "hello";
// def clos = {param -> println "${str1} ${param}"};
// clos.call("groovy!");
// str1 = "welcome";
// clos.call("groovy!");
// Example.Display(clos);
// def lst = [12,13,14,15];
// lst.each {println it};
// def mp = ["name":"jack","age":30];
// mp.each {println it};
// mp.each {println "${it.key} maps to:${it.value}" };
def lst = [1,2,3,4];
lst.each {println it};
println("The list will only display those numbers which are divisible by 2");
lst.each {num -> if(num % 2 == 0) println num};
}
}
浙公网安备 33010602011771号