In Java, to make a class cloneable, we need to implement Cloneable
interface.
Implementing this interface, is just to say that this class supports cloning.
But what is the motive of Java language designers for not making "allowed-to-clone" as default functionality of each class?
We have default implementation for shallow copy already present. Then why this restriction ?
Think about cloning an object with nested properties. How deep recursively do you want to go? This could be tough for the memory, so the developers left it for us to decide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With