H
Hal Vaughan
I'll start by saying I've always had a bit of trouble with OOP and keeping
clear when, in a language like Java, I'm working with a pointer or a new
instance of an object.
As best I can tell, if I have the following:
MyObject myObj = new MyObject;
Vector myVec = new Vector();
myVec.add(myObj);
..
..
..
//here i points to the object we're using
MyObject newObj = (MyObject) myVec.get(i);
It seems that newObj is not the same instance of myObj but a copy of it that
I can alter without effecting myObj. Is that right? (I could have
misunderstood the results when I ran a test.)
If that is right, that by casting, I'm creating a new object, and, as best I
can tell, anything in a Vector is treated as Object and not a type of
object, how can I get an object out of a Vector (or LinkedList or HashMap)
either without casting or by making sure that the resulting object is just
another instance of the one in the Vector?
Thanks!
Hal
clear when, in a language like Java, I'm working with a pointer or a new
instance of an object.
As best I can tell, if I have the following:
MyObject myObj = new MyObject;
Vector myVec = new Vector();
myVec.add(myObj);
..
..
..
//here i points to the object we're using
MyObject newObj = (MyObject) myVec.get(i);
It seems that newObj is not the same instance of myObj but a copy of it that
I can alter without effecting myObj. Is that right? (I could have
misunderstood the results when I ran a test.)
If that is right, that by casting, I'm creating a new object, and, as best I
can tell, anything in a Vector is treated as Object and not a type of
object, how can I get an object out of a Vector (or LinkedList or HashMap)
either without casting or by making sure that the resulting object is just
another instance of the one in the Vector?
Thanks!
Hal