Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cloneable Inteface  RSS feed

 
Amit Tripathi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been having a little confusion regarding the Cloneable interface. Suppose i create a class called Animal and implement the cloneable interface on it. Then i create a subclass called Cat.

When i do,
Cat MyCat = new Cat();
MyCat.clone();

This is allowed.

But when i do, Animal myAnimal = myCat ;
myAnimal.clone();, it says that clone is not visible for this class.

Why is this the case? Should the methods of the class Object not be available to all classes that implement the Cloneable interface, and ofcourse Cat does it as it extends the Animal class.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're creating a clone and than immediately you throw it away again...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!