de en es fr
Let the machine help
Light teasing, exhibition, BDSM, sissyfication, watersports... with sounds and pictures


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Groovy "Feature"
PostPosted: Sat Jan 16, 2021 7:26 pm 
Offline
Veteran
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?


Top
 Profile Send private message 
 
 Re: Groovy "Feature"
PostPosted: Fri Jan 22, 2021 6:31 pm 
Offline
Site Admin
User avatar
Yes, this is the correct behaviour
But you can do a clone :
Code:
def listA = [1, 2, 3]
def listB = listA.clone()



Top
 Profile Send private message 
 
 Re: Groovy "Feature"
PostPosted: Sat Jan 23, 2021 5:52 am 
Offline
Veteran
Ah nice! Sure beats my hand jammed for loop list copy technique ;)


Top
 Profile Send private message 
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010 - 2020
This website uses session cookies only.