4.4Groovy闭包的多参数

来源:互联网 发布:网页美工培训 编辑:程序博客网 时间:2024/06/06 16:57

def tellFortune(closure) {    closure new Date("09/20/2012"), "Your day is filled with ceremony"}// 有两个参数。参数1:Date实例,参数2:字符串tellFortune() { date, fortune ->    println "Fortune for ${date} is '${fortune}'"}
运行结果:

Fortune for Thu Sep 20 00:00:00 CST 2012 is 'Your day is filled with ceremony'

程序分析:

1、闭包中单个参数默认为it,多个参数需要通过参数列出来。

2、符号“->”将将参数名称、闭包主体分开。

原创粉丝点击