groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <Jason.Winneb...@windstream.com>
Subject RE: Bypassing local variables in a closure
Date Mon, 20 Jul 2015 12:17:24 GMT
Yes, I'd advise against aliasing the name, but Closure has a method getDelegate, so you can
just do "delegate.user exists:true" in the closure. If you're saying that you don't control
the closure's code but only the caller, there's nothing (reasonable) you can do -- it's up
to the caller to be able to define their own locals.

Jason

-----Original Message-----
From: Jochen Theodorou [mailto:blackdrag@gmx.org] 
Sent: Saturday, July 18, 2015 2:11 AM
To: users@groovy.incubator.apache.org
Subject: Re: Bypassing local variables in a closure

Am 18.07.2015 02:53, schrieb yaro:
> 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.

normally the solution is to not to use that name as local variable

bye blackdrag

--
Jochen "blackdrag" Theodorou
blog: http://blackdragsview.blogspot.com/

----------------------------------------------------------------------
This email message and any attachments are for the sole use of the intended recipient(s).
Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply email and destroy all copies of the
original message and any attachments.

Mime
View raw message