classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view


Martin Lafaix

> From: "Andreas Zieritz" <[hidden email]>
> This should really be 'basic stuff', I know...
> When I write
> a = 1
> b = a
> b is more or less a pointer to a, it is not a copy. So if I change a, the
> value of b changes, too.
> What if I want a 'copy' of a? (I need that when copying an array).

First, you only need a copy of an object if the object is mutable.
In this case, the object's class often implements the Clonable
interface.  You can then use the object's clone method.

So for example

  a = aMutableClass()
  b = a.clone

will fit your need.

If the object is mutable but does not implement the Clonable
interface, then the fun begin.

But remember that many objects (including Rexx, String, etc.)  are
in fact immutable, and hence the copy is not needed.

[hidden email]
Team OS/2

To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>