Name: gb36485 Date: 04/16/99
I believe that this is a design flaw (or at least anomaly).
In C++ I use special (often protected or private) constructors when I want to create a clone for some special purpose. I'm using Cloneable in Java and overriding clone() when I need to further make copies of objects that my instance has a reference to. In following this paradigm, it would be great if I could just call clone() of every object that is copy-able. But it doesn't seem consistent.
For instance, the String class supports a constructor that looks like this:
String(String)
That's fine. But a the String class it's self does not implement Cloneable even though it is "copy-able". Perhaps there is something "by design" that I'm missing. Otherwise, in future versions of the JDK, perhaps some classes can have constructors that take a single parameter of their own type to make copies, but if they are "copy-able" at all they should all implement Cloneable (i.e., follow the same paradigm). Perhaps it would be more fitting to depreciate any existing constructors of this type and make all the existing (and new) JDK classes implement Cloneable if their instances can be copied.
Can you please reply to this message?
Thanks,
(Review ID: 34922)
======================================================================