Is there a possibility to add `clone()` for go?

like new() and make(), clone() will return a relative type like generic. It is used to deep copy any object.

Clone doesn’t make sense in a language with pointers and private fields. You could end up cloning a lock, for example.

If there is a pointer, it return a new pointer point to new object. It also copy private fields.

That won’t work, if I have a reference to a giant in memory database then clone would copy the entire thing ?

I don’t think clone is the solution you are looking for. What is the original problem that you are trying to solve ?

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.