Ulf Dittmer wrote:I would also note that in a moment of truly bad API design the Cloneable interface does not contain the clone() method.
Ulf Dittmer wrote:
Also, in my experience, the use of clone() in application code is exceedingly rare. It's much more common that a class has a constructor that takes an instance of the class as parameter, and then proceeds to create a clone of that instance.
Ulf Dittmer wrote:Also, in my experience, the use of clone() in application code is exceedingly rare.
Also, in my experience, the use of clone() in application code is exceedingly rare. It's much more common that a class has a constructor that takes an instance of the class as parameter, and then proceeds to create a clone of that instance.
Can you show an example of this? I don't quite follow how that works. Not to hijack this thread from the OP, sorry.
Any exception for array cloning?
There is a difference. Rectangle is a mutable class, so you can usefully create another instance which is equal to another, and change the state of one. You can also use that technique for defensive copies (as in this thread). But String is an immutable class, so you never need to take copies. That is why it doesn't implement Cloneable. You can find lots of discussion about String and the new String("blahblahblah") construct by searching this forum and Java in General.Ulf Dittmer wrote: . . . String has a constructor "String(String)" . . . Rectangle has a "Rectangle(Rectangle)" constructor: . . ..
Ulf Dittmer wrote:Also, in my experience, the use of clone() in application code is exceedingly rare.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Jelle Klap wrote:I'd be very suprised if Java's default serialization mechanism turned out to be faster then a platform native implementation for copying arrays, which is used by System.arraycopy() (and by extension Arrays.copyOf()).
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Winston Gutkowski wrote:If I can find it, I'll post it.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Water proof donuts! Eat them while reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|