commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <>
Subject Re: [beanutils] Why the shallow clone?
Date Thu, 22 May 2003 16:27:45 GMT
On Thursday, May 22, 2003, at 11:02 AM, Christian (SerpentMage) wrote:

> I have been playing around with the clone from BeanUtils.clone and 
> noticed that the clone is a shallow clone only.

yes, BeanUtils.clone is a shallow clone.

> Am I doing something wrong here?


> If so, I noticed from a previous email that it was implemented that way 
> to reflect how Java does a clone.  I can understand that, but then my 
> question is how do you hook into the cloning process?  When java does a 
> clone you can call a clone while the clone is executing.  However, 
> because beanutils is managing the entire process a hook would appear 
> necessary since otherwise you need to manually go through all the classes 
> and do a BeanUtils.clone.  And that I think would seem to be beside the 
> point since the point is to let BeanUtils do everything for you.

what cloneBean does is to create a new instance and then use PropertyUtils.
copyProperties to set the properties on the new instances to the values 
got from the original properties. this will produce a shallow clone.

> Am I missing something here?  Thanks

not sure. maybe you are and maybe you aren't :)

cloneBean produces a shallow clone of the exposed properties. so it's a 
bean-centric cloning (rather than data centric). what did you want 
cloneBean to do?

- robert

View raw message