vector.add(); -- Reference or Object?
Hi all!
I need some help here! =) If i create one object of a class:
Player newPlayer = new Player();
..and then I want to add references (?) to this object in two different vectors;
Vector v1 = new Vector();
Vector v2 = new Vector();
v1.add(newPlayer);
v2.add(newPlayer);
The second vector (v2) doesn't seem to work when i try to get the player like:
Player tempPlayer = (Player)v2.get(0);
..but the first one seems to work (v1).. What the heck is happening? I'm not sure how the add-thing works, but it seems like the object (newPlayer) is _inserted_ in v1, and then when I add newPlayer to v2, there is only rubbish left! :) Why is that? What does add() do? Add the object itself or a reference to the object?
Thanx in advance!
/Mr.Stupid..
|