Hi, all!
When I execute closure.call(), I get an error: No signature of method:
java.lang.Integer.call() for arg types LinkedHashMap.
Rightly so, because local variables are looked up before the delegate and
user (which value is int
5) is enclosed by the closure.
How do I bypass local variables and go straight to delegate?
Perhaps add invokeMethod or getProperty to closure's metaClass?
class SomeClass {
def controllerAction() {
def user = service.currentUser // = 5
someMethod {
user exists: true
}
}
def someMethod(Closure closure) {
closure.delegate = new SomeDelegate()
closure.resolveStrategy = Closure.DELEGATE_ONLY
closure.call()
}
}
--
View this message in context: http://groovy.329449.n5.nabble.com/Bypassing-local-variables-in-a-closure-tp5726326.html
Sent from the Groovy Users mailing list archive at Nabble.com.
|