groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Krzysztof Kowalczyk <kowalczyk.krzysz...@gmail.com>
Subject Re: Closure does not see field when setting value
Date Tue, 08 Nov 2016 13:47:53 GMT
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>



--
View this message in context: http://groovy.329449.n5.nabble.com/Closure-does-not-see-field-when-setting-value-tp5736534p5736543.html
Sent from the Groovy Users mailing list archive at Nabble.com.

Mime
View raw message