On 08.11.2016 22:21, Krzysztof Kowalczyk wrote:
Ok, thanks.

So that would make this.x reference works as expected but still x = 1
would work in surprising way. Why to allow creation of new bindings in
this way at all? Reading bindings, fine, but creating new? To share them
with outside world?

because a script "x = 1" is supposed to work out of the box. You could always have a different script base class.

The behaviour is surprising to me in 2 ways:
First, I do create a new thing even though it "exists".

Binding does not care what already exists.

Second, if I compile it in static way it will behave differently.

and static compilation does not care about dynamic behaviours.

@CompileStatic should behave as I want (I guess), but I can't easily
apply @CompileStatic to a script, can I?

This http://mrhaki.blogspot.de/2016/01/groovy-goodness-customising-groovy.html and this http://mrhaki.blogspot.de/2014/04/groovy-goodness-define-compilation.html might be interesting to you

bye Jochen

Reply via email to