[英]What does -> mean in gradle scripts
gradle腳本中->運算符是什么意思。 這是一件令人討厭的事情嗎? 例如
def configureWarnings = { compiler ->
compiler.args '-Wno-long-long', '-Wall', '-Wswitch-enum', '-pedantic', '-Werror'
}
要么
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
}
}
}
這是閉包中參數的常規語法。 看到這里更多信息
通常,此語法為:
用於將參數與閉包主體分開。
如果您有多個參數,它們將以逗號分隔。
一個簡單的例子是:
def list = ['a', 'b', 'c']
list.each { listItem ->
println listItem
}
這將導致:
a
b
c
在這種情況下,您甚至可以省略參數,而使用本機調用它 。 該代碼將類似於:
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
希望我有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.