Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Programmer > Re: is an objec...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 52628 of 55513
Post > Topic >>

Re: is an object deep-copied when added to a collection?

by "Peter Duniho" <NpOeStPeAdM@[EMAIL PROTECTED] > May 10, 2008 at 11:40 AM

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
 




 6 Posts in Topic:
is an object deep-copied when added to a collection?
lucia.roibal@[EMAIL PROTE  2008-05-10 11:07:15 
Re: is an object deep-copied when added to a collection?
Eric Sosman <esosman@[  2008-05-10 14:18:20 
Re: is an object deep-copied when added to a collection?
"Peter Duniho"   2008-05-10 11:40:12 
Re: is an object deep-copied when added to a collection?
ptomblin+netnews@[EMAIL P  2008-05-11 02:27:51 
Re: is an object deep-copied when added to a collection?
Mark Space <markspace@  2008-05-10 11:39:57 
Re: is an object deep-copied when added to a collection?
Andrea Francia <andrea  2008-05-11 01:22:25 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 19:12:01 CST 2008.