H
Hal Vaughan
This seems to me to be an issue in dealing with pointers and cloning
objects. I understand that if I have two Objects, whether they're
something like a String or an object I define myself, then when I do:
String newString = oldString;
that newString is simply a pointer to oldString so if I change the value in
one, I change the value in the other.
What I'd like to do is copy an object I've created that has a few HashMaps
in it to an entirely new object and make sure they are both separate.
Whenever the data in this program is saved, a backup copy of this object
would be created. That way, while I'm editing data in the program, if I
make a mistake, I can easily restore things to the last time I saved by
copying the back up object to the new object.
This object is essentially a data table and I have several of them, stored
in a Vector. I've read that if I use clone() on a Vector, that a new
Vector is created, but the new one will still point to all the same objects
in the first Vector. If I iterate through the Vector and clone each Object
in it and store each cloned object in a new Vector, will that new Vector
have a copy of equivalent values without them being the same objects?
If that doesn't work, how can I create a backup of an Object so I can change
the values in one while the values in the other stay the same?
Thanks!
Hal
objects. I understand that if I have two Objects, whether they're
something like a String or an object I define myself, then when I do:
String newString = oldString;
that newString is simply a pointer to oldString so if I change the value in
one, I change the value in the other.
What I'd like to do is copy an object I've created that has a few HashMaps
in it to an entirely new object and make sure they are both separate.
Whenever the data in this program is saved, a backup copy of this object
would be created. That way, while I'm editing data in the program, if I
make a mistake, I can easily restore things to the last time I saved by
copying the back up object to the new object.
This object is essentially a data table and I have several of them, stored
in a Vector. I've read that if I use clone() on a Vector, that a new
Vector is created, but the new one will still point to all the same objects
in the first Vector. If I iterate through the Vector and clone each Object
in it and store each cloned object in a new Vector, will that new Vector
have a copy of equivalent values without them being the same objects?
If that doesn't work, how can I create a backup of an Object so I can change
the values in one while the values in the other stay the same?
Thanks!
Hal