Hi guys, based on codes above, seems like List and Str are passed into func/method as value and not reference. Am I correct? If I am, why is it so? I can't seem to find any explanation in the docs.
So if I want to replace the value of the original variable like in Java/C#, how should I do it idiomatically in Fantom?
SlimerDudeWed 25 Jul 2012
Str's are immutable (like in Java) and Lists are passed by ref. What you're doing is re-assigning your local variables v and s and returning them - you're not changing the refs to l1 and s2
if I want to replace the value of the original variable
ikhwanhayat Wed 25 Jul 2012
Hi guys, based on codes above, seems like
List
andStr
are passed into func/method as value and not reference. Am I correct? If I am, why is it so? I can't seem to find any explanation in the docs.So if I want to replace the value of the original variable like in Java/C#, how should I do it idiomatically in Fantom?
SlimerDude Wed 25 Jul 2012
Str's are immutable (like in Java) and Lists are passed by ref. What you're doing is re-assigning your local variables
v
ands
and returning them - you're not changing the refs tol1
ands2
brian Wed 25 Jul 2012
This code:
You are creating a new Int[] and assigning it to v. You probably want something like this if you want to modify in place:
ikhwanhayat Wed 25 Jul 2012
Ah, I see it now. I think I got it mixed up with
out
parameter in C#.Thanks guys!