*
The moose likes Java in General and the fly likes why clone method is provided in object class and not in clonable interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "why clone method is provided in object class and not in clonable interface" Watch "why clone method is provided in object class and not in clonable interface" New topic
Author

why clone method is provided in object class and not in clonable interface

ani jadhao
Ranch Hand

Joined: Dec 23, 2008
Posts: 62
hi all,
I wonder if some one please could clear my confusion.
I have a class which dont implements clonable interface but override a clone method .

When I try to clone the object of my class , it runs fine with no compiler error nor any exception.

-So how will end user know that cloning has heppened properly or not?
-why clone method has been provided in object , why not in clonable?
- if they would not make clonable a marker interface , by providing clone method inside interface , implementers of clonable interface HAS TO implement clone method and user would be sure that cloning has happened because it has implemented clonable and over riddedn clone method?

looking forward for reply....


Yogesh Gnanapraksam
Ranch Hand

Joined: Dec 17, 2009
Posts: 133
Have a look at this bug
http://bugs.sun.com/view_bug.do?bug_id=4098033
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
The java.lang API suggests that you implement Cloneable with a public clone() method,
overriding Object's protected clone() method. This offers added assurance that the clone
operation is properly implemented for your class.

Jim ... ...


BEE MBA PMP SCJP-6
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

By not putting clone() inside the Cloneable interface you are also allowed to keep the clone() method protected for internal use only.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: why clone method is provided in object class and not in clonable interface
 
Similar Threads
clone() method
what is the use of Clonable interface?
some doubts in core java
singleton?
Purpose of Cloneable interface