当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Gradle dependencies groovy closure syntax

问题描述:

Very basic question.

This snapshot in build.gradle :

dependencies {

classpath 'com.android.tools.build:gradle:0.13.2'

}

is supposed to call method dependencies(Closure c) and pass it a closure.

Could someone please explain the syntax of this simple closure

{ classpath 'com.android.tools.build:gradle:0.13.2' }


It is not returning anything, is it ?

网友答案:

http://groovy.codehaus.org/Closures+-+Formal+Definition

Notably:

Closures always return a value. This may occur via either an explicit return statement, or as the value of the last statement in the closure body (e.g. an explicit return statement is optional).

There's not really any syntax to explain; there's a closure, inside it the classpath method is called, and it takes a string argument. Whether or not anything is done with the return value, or whether or not the return value is significant, is a separate issue.

In this case it's not; there's a side-effect of setting the classpath value.

分享给朋友:
您可能感兴趣的文章:
随机阅读: