D
D
DeNissss44442022-02-22 22:24:25
Java
DeNissss4444, 2022-02-22 22:24:25

Why invent clone() when you can use the copy constructor?

I do not quite understand why clone is needed to copy an object, if it's faster to use just a copy constructor. Clone also needs to override the method and implement Clonable, when everything in the constructor is two times. I read various articles about object cloning, but I did not find a normal answer to this question. Can someone explain why we need a separate clone method if a copy constructor is available and which of these two methods is better and more relevant in 22?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2022-02-22
Hasanly @azerphoenix

I think they gave a complete and detailed answer to your question here:
https://stackoverflow.com/questions/2427883/clone-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question