JSON
JSON

Reputation: 5171

Question about "&" in Groovy

like this:
Groovy:

map = ['a':1,'b':2]
doubler = this.&doubleMethod
map.each(doubler)
println map

What's the "&" used for here?

Upvotes: 15

Views: 2966

Answers (1)

Kieron
Kieron

Reputation: 11824

the .& operator is a method reference, i.e. it turns the indicated method into a closure so that it can be passed to other methods that want a closure as an argument.

Upvotes: 19

Related Questions