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

Cloning in Java

 
Anand Jain
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was reading why do we need to clone an object and this is what I got
We clone an object when initializing an object is too expensive So, instead of creating a new object, we can clone an existing one and only change the properties that matter to our new instance.


I didn't get it properly.Could someone please elaborate it or explain it some other way?
 
Stephan van Hulst
Bartender
Pie
Posts: 5810
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you quote your source? It sounds pretty silly.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anand Jain wrote:I was reading why do we need to clone an object and this is what I got
We clone an object when initializing an object is too expensive So, instead of creating a new object, we can clone an existing one and only change the properties that matter to our new instance.


This makes no sense. There's no reason to think cloning will be any faster than creating a new object the "normal" way. It sounds like the author doesn't know what he's talking about.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic