aspose file tools*
The moose likes Java in General and the fly likes Diff. between Object Cloning & Object Creation 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 » Java in General
Bookmark "Diff. between Object Cloning & Object Creation" Watch "Diff. between Object Cloning & Object Creation" New topic
Author

Diff. between Object Cloning & Object Creation

ChandraMouli Vidiyala
Greenhorn

Joined: Dec 19, 2002
Posts: 12
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

Joined: Oct 29, 2001
Posts: 8927
    
    9

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Diff. between Object Cloning & Object Creation