File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cloneable interface

 
Nikhil Sun
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I want an object to be cloned.So I would implement a public/protected Object clone() method inside its class.My question is whether I need to compulsorly specify that this class implements Cloneable or is it optional?
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So I would implement a public/protected Object clone() method inside its class.


You need not implement Object clone() method inside your class. You just need to make a call.

To answer your second question, yes it is mandatory for the class to implement Cloneable interface.

And best way to figure out whether it is mandatory or not is just to write a test program and run it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably would wish to implement a clone() method. There is recent discussion on this thread about how one might do it.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic