I wanted to know how Java does Object Cloning. But when I read the Object.java class I saw that it was not defined in it. Im confused. I really dont know who internals of java are implemented. It would be nice if someone could help me with this.....

protected native Object clone() throws CloneNotSupportedException;

Notice the native keyword. This means that the method is not implemented using Java, but using native code (C/C++) using the Java Native Interface (http://java.sun.com/docs/books/jni/).

Edited 5 Years Ago by nmaillet: n/a

The API doc does say protected Object clone() yes. The source code, shows it with the native keyword.

What doc are you getting that from?
My API doc has this:
protected Object clone()

Just open the class in IDE and get source (that is how it does work in IntelliJ), then you can see internal structure :)

Edited 5 Years Ago by peter_budo: n/a

There's a load of non-Java-language stuff in the source code download, including C code. I haven't looked at that, but you may find it there?

Oh Thank you. My first guess would be that it would make a memory copy. But Ill try to lookup the source code to see if I can find stuff..

Thanks DW team!!!!

This question has already been answered. Start a new discussion instead.