2016-04-26 125 views
0

- >運算符在gradle腳本中表示什麼?這是一件很時髦的事情嗎?例如。- >在gradle腳本中的含義

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 
     } 
    } 
    } 
+0

http://groovy-lang.org/closures.html –

回答

1

它是在一個封閉的參數常規語法。 See here以獲取更多信息

0

在常規,此語法:

用於將參數封閉體分離。

Closures Refference

他們是用逗號分隔的,如果你有一個以上的參數。

一個簡單的例子是:

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 

希望我已經幫助。