16 Aug 2012 08:00
[groovy-user] Exact difference between Script class and Binding class in groovy.
Consider this code:
x = 10
10.times{
x++
}
assert ​binding.getVariable("x") == 20
As far, I'm concerned this is what happening in the above code: Script class
has a reference to the variable x which has value 10 and it calls the times
closure which will access the variable x from Script. So basically the
scoping of x is been done by Script class.
But I wonder when binding came into the picture? In sense, I haven't called
new Binding() or anything, but still its there.
I'm bit confused with it. What is the exact use of binding? Does Script
class creates binding, if so that is how it manages scoping of x within
times method?
Thanks in advance.
--
View this message in context: http://groovy.329449.n5.nabble.com/Exact-difference-between-Script-class-and-Binding-class-in-groovy-tp5710950.html
Sent from the groovy - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
(Continue reading)
RSS Feed