June 04, 2004
On Fri, 4 Jun 2004 05:27:37 +0000 (UTC), Kevin Bealer wrote:

> In article <c9or5a$1u4v$1@digitaldaemon.com>, Derek Parnell says... ..
>>I might need one to restore a value on transaction backout.
>>
>>   Int oldVal;
>>
>>   oldVal = a;
>>
>>   a = a + b;
>>   if (DoSomething(a) == 0)
>>      // Restore previous value.
>>      a = oldVal;
> 
> Assuming no bugs, this example will work without deep copy.  The "+" creates a new object; the oldVal still points to the old version.  Immutable means that objects never change.  "a=a+b" points the reference a at a new object which is the sum of a and b.

Thanks. This all makes good sense. I didn't realize, but should have, that the '+' forced a new instance to be created.

-- 
Derek
Melbourne, Australia
4/Jun/04 5:05:21 PM
1 2 3 4 5 6
Next ›   Last »