Object.clone()?

114 views
Skip to first unread message

Matt O'Connor

unread,
Jul 3, 2008, 2:03:30 PM7/3/08
to Google Web Toolkit
Hey all, I've been using GWT for the last 2 months and really like it.

I'm currently using 1.5RC1 for development.

I was wondering about Object.clone() though. The Javadocs describe it
as being implemented, but when I attempt to implement Cloneable and a
clone() method that calls Object.clone(), the GWT compiler says that
method doesn't exist. I think I've also seen the GWT compiler complain
about CloneNotSupportedException not existing.

In the following thread
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/d1481892612273e5/c0af1c9f4ecc3148?lnk=gst&q=Clone#c0af1c9f4ecc3148
, the use of Prototype's Object.clone is discussed. The basic
implementation is (well, it uses [].concat(object) for arrays):

clone = function(object) {
var clone = {};
for(var prop in object)
clone[prop] = object[prop];
return clone;
}

As Java's Object.clone() method performs just a shallow copy, this
implementation would, at first glance, appear to satisfy that
requirement. Is there a reason this hasn't been implemented (like it
doesn't work or doesn't copy methods or something else obvious)?

thanks,
Matt
Reply all
Reply to author
Forward
0 new messages