When converting a method to closure using a notation . & you do not consider parameters. f. & method (6) is the same as calling f.method (6), which will return 16, so in your example you pass 16 to invokeClosure, not to closure. This throws the following exception because the Integer class does not have a call method:
Exception: missing method signature: java.lang.Integer.call ()
The method pointer for f.method in invokeClosure is passed below and will be what you normally use. &.
class Foo { def method(def param) { param + 10 } } def invokeClosure = {Closure closure -> return closure.call(6)
As you indicated, the following will work:
invokeClosure {f.method(6)}
This is because you go through a closure that takes no parameters, so the clos.call () function works in this case.
John wagenleitner
source share