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.....

7 Years
Discussion Span
Last Post by stevanity
Featured Replies
  • 1

    How many other methods are native? I'll bet a lot. Read More

  • 3
    ~s.o.s~ 2,560   7 Years Ago

    Adding on to others, it also pays to know that [URL="http://www.artima.com/intv/bloch13.html"]cloning in Java is pretty much broken[/URL] and for practical purposes you are better off using other alternatives (hand rolled copy constructor). Read More

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 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 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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.