groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: Closure does not see field when setting value
Date Tue, 08 Nov 2016 16:47:58 GMT


On 08.11.2016 14:47, Krzysztof Kowalczyk wrote:
> Jochen Theodorou wrote
>> there we access the field only directly if [...]  an explicit this is
>> used.
>
> So should prefixing it with "this" should change the behaviour?
> It does not:
>
> <pre>
> ‚Äčimport groovy.transform.Field
>
> @Field
> int x = 0
>
> a {
>     assert this.x == 0
>     this.x = 1
>     assert this.x == 1
> }
>
> assert x == 0
>
> def a(Closure c) {
>     c()
> }  ‚Äč
> </pre>

ah right, sorry, this is on a long list of things to be change, but yes, 
it does not solve the problem. You can solve it by using this.@x, since 
that forces field access, but I think you may still get into trouble 
with subclasses...

bye Jochen

Mime
View raw message