If I have a piece of code like this:
MyClass[] objArray = new MyClass[7];
//assign values to objArray
//do something here
//sometime later
MyClass newObj = new MyClass();
objArray[3] = newObj;
The last statement above will do the following:
- copy all the contents of the
newObjto the space referred to by objArray[3].
Questions
Am I right?
Shallow copy or deep copy?
If it is shallow copy, how can I make the deep copy possible?
objArray[3] = newObj;Does this rule applies to other Java container types, such as Queue, List, ...?