Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
ani jadhao
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this bug
http://bugs.sun.com/view_bug.do?bug_id=4098033
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ... ...
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By not putting clone() inside the Cloneable interface you are also allowed to keep the clone() method protected for internal use only.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic