4.3Groovy闭包的使用
来源:互联网 发布:编程初学 编辑:程序博客网 时间:2024/06/13 18:33
// 定义类class Equipment { // 属性:计算器 def calculator // 构造方法 Equipment(cacl) { // 接受闭包参数 calculator = cacl } // 方法:模拟器 def simulate() { println "Running simulation" // 调用闭包函数 calculator() }}// 写法1:直接传入闭包def eq1 = new Equipment({ println "Calculator 1" })// 写法2: 将闭包赋值给变量def aCalculator = { println "Calculator 2" }def eq2 = new Equipment(aCalculator)def eq3 = new Equipment(aCalculator)eq1.simulate()eq2.simulate()eq3.simulate()
运行结果:Running simulation
Calculator 1
Running simulation
Calculator 2
Running simulation
Calculator 2
阅读全文
0 0
- 4.3Groovy闭包的使用
- Groovy的闭包
- Groovy的闭包
- Groovy的闭包
- Groovy的闭包
- Groovy的闭包
- Groovy的闭包示例
- groovy 闭包的理解
- 【Groovy】闭包的上下文
- Groovy 解析json和闭包的使用
- (2.2.9.3)groovy的闭包
- 4.4Groovy闭包的多参数
- Groovy闭包
- Groovy 中的闭包
- groovy 闭包
- Groovy 闭包
- groovy 闭包
- Groovy闭包理解
- csdn博客设置评论权限
- Python结合图灵机器人
- 正则表达式Pattern和Matcher详解
- 11.12帮女朋友写东西
- java实现https双向认证
- 4.3Groovy闭包的使用
- Paxos 一致性算法原理剖析(-)
- ORA-12537错误处理一例
- JS中DOM的节点
- Node监控文件夹中的文件改变事件
- 非常可乐
- 724. Find Pivot Index
- Material Design Android控件介绍
- Intel 100芯片组如何安装Win7