File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clone

 
Rakesh Sharma
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what are clone objects and how it is useful?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clone is not an object, it is a method for copying an object. Normally if you have a variable and it is "equal" to an object then the variable holds a reference to the location of the object.
Circle c1 = new Circle();
Circle c2 = new Circle();
c1 = c2;
Now you have 2 circles both containing the reference to a single object.
If you actually want to create a deep copy of the object (not just a copy of the reference), then you need to clone it.
c1 = c2.clone();
Now you have two object that are exactly ALIKE.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic