• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please help me out with clone()  RSS feed

 
Vasudhaiv Naresh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
can anybody please let me know what this clone() method is? And what is it used for? Going through the API I found that it is used to return a copy of an object, what I'm unable to understand is - "what it is required for?"

Thanks,
Naresh
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea is that a copy of an object can be manipulated and examined by other objects in the application with no risk of damaging the original object. The standard clone method returns a "shallow" clone; you may need a "deep" clone for real security.

Start reading in the Object class here and the Java Tutorial.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Click on the "Effective Java" link from the tutorial link I quoted, then "sample chapters" then "chapter 3."
 
Vasudhaiv Naresh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ritchie, that was a real helpful one.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!