Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question about "&" in Groovy

Tags:

groovy

like this:
Groovy:

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

What's the "&" used for here?

like image 236
JSON Avatar asked Feb 04 '09 03:02

JSON


1 Answers

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.

like image 184
Kieron Avatar answered Oct 17 '22 11:10

Kieron