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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cloneable" Watch "Cloneable" New topic
Author

Cloneable

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
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.


<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Cloneable