Re: is an object deep-copied when added to a collection?
by Eric Sosman <esosman@[EMAIL PROTECTED]
>
May 10, 2008 at 02:18 PM
lucia.roibal@[EMAIL PROTECTED]
wrote:
> Say, I do the follow,
>
> Date d=new Date();
>
> ArrayList<Data> alist= 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.
--
Eric Sosman
esosman@[EMAIL PROTECTED]