请问大家
```
tasks.withType(JavaCompile) {
options.encoding='UTF-8'
}
```
这面这段代码用groovy怎么理解。是tasks.withType(JavaCompile)返回的结果进行循环遍历吗?
请问大家
```
tasks.withType(JavaCompile) {
options.encoding='UTF-8'
}
```
这面这段代码用groovy怎么理解。是tasks.withType(JavaCompile)返回的结果进行循环遍历吗?
其实是withType 方法有两个参数,第一个是个对象,第二个是的闭包Closure
写个简单的例子:
Tasks 类:
package com.test class Tasks { def list = ["a", "b", "c"] def withType(a,b){ println a list.each { b.call() } } }
运行:package com.test def tasks = new Tasks() tasks.withType("abc"){ println "...." }
实际中还要用到委托delegate,就不写了,楼主可以自己研究下