- package com.dj.groovy
- /**
- * User: ldj
- * Date: 2023/10/29
- * Time: 2:51
- * Description: No Description
- */
- class groovy01 {
-
- static void main(String[] args) {
- addition((a, b) -> {
- int result = a + b
- print("I'm a closure; a + b= " + result)
- })
- }
-
- def static addition(Closure closure) {
- int a = 10
- int b = 8
- println("closure begin")
- //调用闭包程序,单独把一段小程序提取出来
- def result = closure(a, b)
- println()
- println("closure end")
- }
-
- }
2. 数组遍历