什么 - >在gradle脚本中表示

时间:2016-04-26 16:45:33

标签: gradle groovy

什么是 - >运算符在gradle脚本中的意思。这是一个时髦的事情吗? E.g。

def configureWarnings = { compiler ->
      compiler.args '-Wno-long-long', '-Wall', '-Wswitch-enum', '-pedantic', '-Werror'
}

OR

all { binary ->
    binary.component.sources.cpp.libs.each { lib ->
      if (lib instanceof Map && lib.containsKey('library') {
        //blah
      }
      if (lib instanceof Map && lib.containsKey('library')) {
        //blah
      }
    }
  }

2 个答案:

答案 0 :(得分:1)

它是闭包中参数的groovy语法。 See here了解更多信息

答案 1 :(得分:0)

在groovy中,这个语法:

  

用于将参数闭包主体分开。

Closures Refference

如果您有多个参数,则以逗号分隔。

一个简单的例子是:

def list = ['a', 'b', 'c']

list.each { listItem ->
    println listItem
}

这将导致:

a
b
c

在此上下文中,您甚至可以省略该参数,并使用本机调用 it 。代码类似于:

def list = ['a', 'b', 'c']

list.each {
    println it
}

结果将,而且应该是相同的。

例如,如果你有地图,你可以将它的键和值分开:

def map = ['Key_A':'a', 'Key_B':'b', 'Key_C':'c']
map.each { key, value ->
    println "$key has the value $value"
}

当然,结果将是:

Key_A has the value a
Key_B has the value b
Key_C has the value c

希望我能帮到你。

相关问题