Groovy web console

subscribe to the feed Subscribe
to this
site

Groovy List not reflecting changes to List passed in when updated using List + sign overloading within method or closure

Published 2 weeks ago by I miss the shuttle with tags groovy list
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
println GroovySystem.version

List<String> b = ['man', 'lady']

def x = { List<String> p ->

    println delegate.getClass().getName()
    List<String> inx = ['dog','cat']
    /*for (String l : inx) 
    { 
        p.add(l) 
    }*/
    p = p + inx

}

def xmethod(List<String> p)
{
    List<String> inx = ['monkey','lion']
    /*for (String l : inx) 
    { 
      p.add(l) 
    }*/
    p = p + inx
    
}

x( b )
println b

xmethod( b )
println b

List<String> outside = ['building', 'house']
b = b + outside
println b