A question about this at the top level

View: New views
2 Messages — Rating Filter:   Alert me  

A question about this at the top level

by Russ Abbott :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Why does this happen?

y = "y"
assert y.is(this.y)
println "OK so far!" // => OK so far!"
 
def z = "z"
assert z.is(this.z)  // =>  groovy.lang.MissingPropertyException: No such property: z for class: Script0



-- Russ


Re: A question about this at the top level

by Michael Baehr-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

y goes into the binding (no def), while z is a local variable.

In a script, "this" is resolved to the binding!

Michael

Am 06.07.2008 um 22:22 schrieb Russ Abbott:

y = "y"
assert y.is(this.y)
println "OK so far!" // => OK so far!"
 
def z = "z"
assert z.is(this.z)

LightInTheBox - Buy quality products at wholesale price