Results 1 to 2 of 2
  1. #1
    esolve is offline Member
    Join Date
    Mar 2015
    Posts
    56
    Rep Power
    0

    Default there is clone() method in object, why do we still need cloneable interface?

    are there any reasons?
    thanks!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: there is clone() method in object, why do we still need cloneable interface?

    The clone() method by default does a shallow copy (i.e. other objects are not copied recursively). But trying to use this without implementing
    the marker interface Cloneable will generate a CloneNotSupportedMethod exception. The marker simply states that the author of the class
    has identified the class has sufficient (but perhaps not complete) cloning capability. For a more extensive cloning (perhaps a deep copy), the
    clone method must be overridden and appropriate code added. Any inefficiencies in the Cloneable class should be identified in the class' API
    documentation.

    Regards,
    Jim
    Last edited by jim829; 12-12-2015 at 08:27 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 3
    Last Post: 11-20-2012, 08:44 PM
  2. Cloneable interface
    By diamonddragon in forum New To Java
    Replies: 1
    Last Post: 02-01-2012, 10:55 AM
  3. Why is clone() not in the Clonable Interface?
    By garyiskidding in forum Advanced Java
    Replies: 4
    Last Post: 05-29-2011, 04:27 AM
  4. clone method
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 01-30-2008, 10:47 AM
  5. How to clone a JAXB object ?
    By simon in forum Advanced Java
    Replies: 1
    Last Post: 07-15-2007, 12:56 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
  •