+
 新版

Gradle和Groovy的问题

林泳坛 发布于 2015/08/25 16:20
阅读 1K+
收藏 0

请问大家

```

tasks.withType(JavaCompile) {

    options.encoding='UTF-8'

}

```

这面这段代码用groovy怎么理解。是tasks.withType(JavaCompile)返回的结果进行循环遍历吗?

加载中
0
vidy_tu
vidy_tu

其实是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,就不写了,楼主可以自己研究下
0
林泳坛
林泳坛
明白了,多谢。委托这个我知道。
0
wjghenhao
wjghenhao
Gradle非要在线安装带MyEclipse么?我这边翻不了墙,能不能再本地装到MyEclipse,求教
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部