SexScripts : Groovy "Feature" - https://ss.deviatenow.com:443/viewtopic.php?f=4&t=1020 | Page 1 of 1 |
Groovy "Feature" |
ispank [ Sat Jan 16, 2021 7:26 pm ] |
---|---|
I was working on my new script yesterday and encountered this interesting "feature" of groovy. def listA = [1, 2, 3] def listB = listA listB.remove(1) show(listA) results in: [2,3] So I guess when you set listB to listA, they are both pointing to the same memory location? Can anyone confirm this is the correct behavoir? |
Re: Groovy "Feature" |
doti [ Fri Jan 22, 2021 6:31 pm ] |
---|---|
Yes, this is the correct behaviour But you can do a clone : Code: def listA = [1, 2, 3]
def listB = listA.clone() |
Re: Groovy "Feature" |
ispank [ Sat Jan 23, 2021 5:52 am ] |
---|---|
Ah nice! Sure beats my hand jammed for loop list copy technique |
Page 1 of 1 | All times are UTC + 1 hour [ DST ] |