I have the following two Vector objects in java.
Vector<SomeClass> obj1;
Vector<SomeClass> obj2;
The class SomeClass has an int variable a.
Assume obj2 is empty and obj1 has some elements in it. Suppose I do this:
obj2.add(obj1.firstElement());
obj2.firstElement().a = 10; // obj2.firstElement() will be the object that was
//added above because obj2 was empty at first
Would this change the value of a in obj1.firstElement() too?
Basically I just want to know if these Vector operations are done by reference or value. My guess is that they are done by reference and this change will be reflected in obj1.firstElement() too.
You are right, the reference is copied (shallow copy) and so the change is reflected also in the original vector.