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 2 of 6 Topic 52628 of 55513
Post > Topic >>

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]

 




 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:31:22 CST 2008.