How does clone work under the hood?

protected native Object clone(). I don’t know exactly (I need to take a look at the native code) but it makes a new instance of the object inside the JVM and copies all fields.

But you should avoid using clone() – it is hard to get it right. Look at this question for more details

Leave a Comment