非常基本的问题 .
build.gradle 中的此快照:
build.gradle
dependencies { classpath 'com.android.tools.build:gradle:0.13.2' }
应该调用方法 dependencies(Closure c) 并传递一个闭包 .
dependencies(Closure c)
有人可以解释这个简单闭包的语法 { classpath 'com.android.tools.build:gradle:0.13.2' }
{ classpath 'com.android.tools.build:gradle:0.13.2' }
它没有返回任何东西,是吗?
http://groovy.codehaus.org/Closures+-+Formal+Definition
值得注意的是:
闭包始终返回值 . 这可以通过显式return语句或闭包体中最后一个语句的值(例如显式return语句是可选的)发生 .
有's not really any syntax to explain; there'是一个闭包,在其中调用了 classpath 方法,它接受一个字符串参数 . 无论返回值是否完成,或返回值是否重要,都是一个单独的问题 .
classpath
在这种情况下,它不是;设置类路径值会产生副作用 .
1 回答
http://groovy.codehaus.org/Closures+-+Formal+Definition
值得注意的是:
有's not really any syntax to explain; there'是一个闭包,在其中调用了
classpath
方法,它接受一个字符串参数 . 无论返回值是否完成,或返回值是否重要,都是一个单独的问题 .在这种情况下,它不是;设置类路径值会产生副作用 .