Search code examples
javaclone

clone () implementation in Object class


I was reading this article and it says that

Object's clone method is very tricky. It's based on field copies, and it's "extra-linguistic." It creates an object without calling a constructor".

All I see in the grep code is the following line :

protected native Object clone() throws CloneNotSupportedException;

What am I missing here ?


Solution

  • You're missing the native which means it's implemented in non-Java code (in this case it's implemented in the JVM itself).

    That's because the exact functionality of clone can not be implemented in Java code (which makes it so problematic).