變量聲明:
{
int
,String
=>
Number?
throws
?IOException}?xyzzy;
將求和功能賦值給變量plus:
{
int
,
int
=>
int
}?plus?
=
?{
int
?x,?
int
?y?
=>
?x
+
y};
循環遍歷map中的entry:
<
K,V,
throws
?X
>
void ? for ?eachEntry(Map < K,V > ?map,?{K,V => void ? throws ?X}?block)
???????? throws ?X?{
???? for ?(Map.Entry < K,V > ?entry?:?map.entrySet())?{
????????block.invoke(entry.getKey(),?entry.getValue());
????}
}
void ? for ?eachEntry(Map < K,V > ?map,?{K,V => void ? throws ?X}?block)
???????? throws ?X?{
???? for ?(Map.Entry < K,V > ?entry?:?map.entrySet())?{
????????block.invoke(entry.getKey(),?entry.getValue());
????}
}
Java5中添加的Generic(泛型)就已經蠻麻煩了,東個尖括號< >西個尖括號< >。Java7也不甘示弱,東個大括號{ }西個大括號{ }??磥鞪ava擁有巨斧后著實會強大許多,而Java程序員也不得不練就能揮舞巨斧的臂膀和身軀。同道們,讓我們一起修煉吧!
參考資料:Closures for the Java Programming Language (v0.5)
附:Groovy輕松入門——Grails實戰之GORM篇