Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cloneable

 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Harshit Rastogi
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48642
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic