• Post Reply Bookmark Topic Watch Topic
  • New Topic

What time should I use clone method?  RSS feed

 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone:
There is a problem puzzled me all the time. You know,If I want to use a object I could use the code:
Class A=new Class(); I get a object A so I can use it. But there is a method called "clone".It's function is copy a object.But Why jdk have this method.Is there any useful ? :roll:
I mean that what situation should I use the "clone " method?
Thks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yashnoo, please take the time to make sure that you are posting a question to the correct forum. This obviously has nothing to do with JSP, but rather is clearly a Java in General question.
thanks,
bear
JSP Forum Bartender
P.S. Moving to the Java in General(intermediate) forum.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yashnoo
Please refer to a book "Thinking in Java" and read about clonning from there.
Basically, clonning is required when we want to make a copy of the object. Meaning when we want to create another object with the same state as some other object. This could be helpful in various scenarios like making objects non-mutable etc...you should get the idea when you read the book I suggested..
Thanks
Maulin
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!