On Sat, 10 May 2008 11:18:20 -0700, Eric Sosman =
<esosman@[EMAIL PROTECTED]
> wrote:
> lucia.roibal@[EMAIL PROTECTED]
wrote:
>> Say, I do the follow,
>> Date d=3Dnew Date();
>> ArrayList<Data> alist=3D new ArrrayList();
>> alist.add(d);
>> //modify d
>> will the element d in the alist also modified?
>
> Yes. Collections do not contain objects, but references
> to objects. Both `d' and a reference somewhere in `alist'
> are pointing to the same object instance, so any changes to
> that object are visible by following either reference.
To the OP: note that while the answer to the question in the message is =
=
"yes", that's not the answer to the question in the subject. Objects =
_aren't_ "deep copied" when added to a collection. They aren't even =
"shallow copied". Only the reference to the object is copied to the =
collection. The object isn't copied at all, deep or otherwise.
Pete


|