Deep versus Shallow object copies

55 views
Skip to first unread message

Paul Ford

unread,
Apr 4, 2012, 11:06:02 AM4/4/12
to Google Documents List API
To all,

I'm curious as to the level at which object copies occur. For example:

If in java is perform the following

Let's assume that entry is of type DocumentListEntry and it contains a
valid populated entry.

DocumentListEntry copiedToEntry = new DocumentListEntry(entry);
'
How deep does this copy go? Are all primitive just copied or are List
also copied (e.g. ParentLinks)?

Or in order to complete copy an entries attributes that we have to
literally enumerate all attributes of entry and links, etc; as
follows:

copiedToEntry.setAttribute(entry.getAttribute); //for primitives

for (Link links : entry.getParentLinks()) {
Link newLink = new Link();
newLink.setAttribute(link.getAttribute());
copiedToEntry.setLink(newLink);
}

etc, etc;

thanks

paul

Ali Afshar

unread,
Apr 4, 2012, 11:14:12 AM4/4/12
to google-docum...@googlegroups.com
Hi Paul,

They are shallow copies which share an EntryState, here is the
documentation string:

/**
* Copy constructor that initializes a new BaseEntry instance to have
* identical contents to another instance, using a shared reference to
* the same {@link EntryState}. {@link Kind.Adaptor} subclasses
* of {@code BaseEntry} can use this constructor to create adaptor
* instances of an entry that share state with the original.
*/

http://code.google.com/p/gdata-java-client/source/browse/trunk/java/src/com/google/gdata/data/BaseEntry.java

--
Ali Afshar | www.googplus.org/ali | Google Developer Relations

Reply all
Reply to author
Forward
0 new messages