aspose file tools*
The moose likes Beginning Java and the fly likes Cloneable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cloneable" Watch "Cloneable" New topic
Author

Cloneable

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 629
When to use a cloneable class and why? Can a final class be cloneable? If not, why? If yes, why? Can anyone please answer this question?

Thanks.
[ November 13, 2008: Message edited by: Arjun Reddy ]

Be Humble... Be Nice.
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
Originally posted by Arjun Reddy:
When to use a cloneable class and why? Can a final class be cloneable? If not, why? If yes, why? Can anyone please answer this question?

Thanks.

[ November 13, 2008: Message edited by: Arjun Reddy ]


About Cloning

CLoning of ojbect is only possible if the Class implements Cloneable interface. So an true final class will not want to make its objects clone and it wont implement the interface.


My Techie Blog - Java Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39877
    
  28
What is wrong with a final class being cloned? If you mean immutable, there is no point in cloning immutable objects, so immutable classes don't usually implement the Cloneable interface.

A lot of people think cloning is a bad idea; see for example "Effective Java" by Joshua Bloch.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cloneable