like this:
Groovy:
map = ['a':1,'b':2]
doubler = this.&doubleMethod
map.each(doubler)
println map
What's the "&" semanteme used here?
like this:
Groovy:
map = ['a':1,'b':2]
doubler = this.&doubleMethod
map.each(doubler)
println map
What's the "&" semanteme used here?
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.