Results 1 to 2 of 2
  1. #1
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Cloneable interface

    If say:

    Java Code:
    public class Circle  extends GeometricObject implements Cloneable {
        private double radius;         
    
        @Override
        protected Object clone() {
            Circle c = null;
            try {
                c = (Circle) super.clone();
            } catch (CloneNotSupportedException e) {
            }
            return c;
        }        
    }
    If try to go to source code of super.clone() method it points to Object class and that is ok, but I can't see any implementation of this method there, how object is beeing actually cloned.
    Where can I find that implementation?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Cloneable interface

    It's a native operation.
    It essentialy copies the contents of the object it's been called on (a shallow copy).
    Unless the object in question does not implement Cloneable in which case it throws an exception.

    This is all in the documentation for clone().

Similar Threads

  1. Why is clone() not in the Clonable Interface?
    By garyiskidding in forum Advanced Java
    Replies: 4
    Last Post: 05-29-2011, 03:27 AM
  2. interface help
    By alpdog14 in forum New To Java
    Replies: 3
    Last Post: 05-04-2011, 11:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •