# Groovy打高尔夫球的秘诀

14

1

Armand

@Alison：我感到很难过，因为此站点上没有Groovy的高尔夫秘诀:(

2

Armand

5

```def a（b）{打印b}
```

```a = {打印}
```

```c =“ abc”
d = [“ a”，“ b”，“ c”]

```

`断言d * .size（）== d.collect {it.size（）}`

``````e = [54,5,12]
assert e.sort{a,b->a<=>b}==e.sort{a,b->a<b?-1:+1}
assert e.sort{a,b->a<=>b}==e.sort{a,b->if (a>b) {return(-1)} else {return(+1)}}
``````

``````assert "123" as int == "123".toInteger()
``````

cfrick

3

``````''.metaClass.r<<{i->(int)Math.random()*i}
''.r(12)
``````

``````0.metaClass.r<<{i->(int)Math.random()*i}
0.r(12)
``````

``````r={(int)Math.random()*it}
r(12)
``````

2

## `grep` 很短，可以解决几个问题

1
`'ABC XYZ'as Set`是一个短字符，并且在大多数相同的地方都可以使用
Marty Neal

2

``````def users = [[user:'A',id:1],[user:'B',id:2],[user:'C',id:3]]
``````

``````def userIds = users*.id // [1, 2, 3] no explicit loops!
``````

``````<select id="users" multiple="true" name="users">
<option value="193">User A</option>
<option value="378">User B</option>
<option value="377">User C</option>
</select><%-- No Grails tags for now --%>
``````

``````def aListOfUsers = User.getAll(params.list('userIds'))
``````

1

Victor F

2

Beta Decay
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.