Groovy web console

subscribe to the feed Subscribe
to this
site
whatIsWrongWithVariableLifecycle (via #groovywebconsole)
tweet this snippet Tweet
this
script

whatIsWrongWithVariableLifecycle

Published 2 months ago by Michele Alberto with tags variable groovy lifecycle
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def foo(x){
    a= x // local variable
    def b= x // defined local variable 
    many = [:]
    many["a"]={a}
    many["b"]={b} 
    many["c"]={x} //the function argument
    many
}

def getValues(m){
    [m.a(),m.b(),m.c()]
    }


m1 = foo("A")
m2 = foo("!A")
assert (['A','A','A'] == getValues(m1))