Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diff. between Object Cloning & Object Creation

 
ChandraMouli Vidiyala
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could any one clarify what is the difference between creation of object through the constructor and cration via object cloning. What are the benifits of cloning?

Thanks in advance.

-Mouli.
 
Joe Ess
Bartender
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating an instance using the constructor may or may not initalize fields. Using clone() will initalize the fields of an instance to be identical to the original instance. It saves you the extra steps of creating a new instance and getting/setting the first instance's values on the second. this article does a good job of explaining the purpose of clone() and the pitfalls of using it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic