Thursday, 15 July 2010

java - Copy constructor over assignment -


After doing a lot of searching, at least I helped understand the difference between copy constructor and assignment operator. Br> My question is about this line
example is to be destroyed and if it has internal dynamic memory then it has to start again
if I start an example I like the object copyObj = null; Assign and then copyObj = realObj , yet what remains of overhead (destruction and resuscitation)?
If not, in this scenario, why should I use copy maker instead of direct director? Concept of using a copy maker by overriding =

  public class myType {private string myField; Public MyType (MyType Source) {this.myField = source.myField; }}   

A copy constructor is a manufacturer who takes a similar type of parameter and copies all of its values, it is used to get a new object with the same status is.

  MyType Basic = New MyType (); MyType Copy = new MyType (original); // After the original / = copy copy will be false and original. Angle (copy) should be correct MyType referenceCopy = root / original after here == Reference code will be correct and original.Akal (reference copy) will also be true   

= The operator does the same: assigning an orange to a variable. It does not generate overhead The different thing in the runtime is that the constructor is a call.

No comments:

Post a Comment