Skip to main content

Timeline for answer to Copy constructor versus Clone() by Grant Crofton

Current License: CC BY-SA 4.0

Post Revisions

10 events
when toggle format what by license comment
Mar 24, 2023 at 12:11 history edited Glorfindel CC BY-SA 4.0
broken link fixed, cf. https://meta.stackoverflow.com/a/406565/4751173
Jul 27, 2010 at 18:37 comment added John Warlow @Grant Crofton - exactly :-) I'll have to examine the implementation code to find out :-(
Jul 27, 2010 at 18:07 comment added Grant Crofton @JLWarlow - but does it do a shallow copy or a deep copy?! :-)
Jul 27, 2010 at 17:44 comment added supercat Has anyone seen a use where iCloneable was used on an object of unknown type? The whole point of interfaces is that they can be used on objects of unknown type; otherwise one may as well simply make Clone be a standard method which returns the type in question.
Jul 27, 2010 at 16:03 comment added John Warlow Bugger, I've come across some of our code that implements ICloneable :-(
Jul 27, 2010 at 15:58 comment added Grant Crofton @Marc, @Kent - yeah fair point, the constructor probably isn't a good idea either.
Jul 27, 2010 at 15:56 comment added Grant Crofton @Jon - The reactoring's never finished!
Jul 27, 2010 at 15:56 comment added Kent Boogaart I'd argue that a constructor is almost as unclear as the ICloneable interface - you'd have to read the API docs/code to know it does a deep clone or not. I just define an IDeepCloneable<T> interface with a DeepClone() method.
Jul 27, 2010 at 15:54 comment added Marc @Grant, how does the constructor relay intent? IOW, if an object took itself in the constructor, is the copy deep or shallow? Otherwise, I agree completely with the DeepCopy() (or otherwise) suggestion.
Jul 27, 2010 at 15:50 history answered Grant Crofton CC BY-SA 2.5