Clone() vs Copy constructor- which is recommended in java -
Clone() vs Copy constructor- which is recommended in java -
this question has reply here:
clone() vs re-create constructor vs mill method? 7 answersclone method vs re-create constructor in java. 1 right solution. utilize each case?
clone broken, dont utilize it.
the clone method of object class magical method no pure java method ever do: produces identical re-create of object. has been nowadays in primordial object superclass since beta-release days of java compiler*; , it, ancient magic, requires appropriate incantation prevent spell unexpectedly backfiring
prefer method copies object
foo copyfoo (foo foo){ foo f = new foo(); //for properties in foo f.set(foo.get()); homecoming f; }
read more http://adtmag.com/articles/2000/01/18/effective-javaeffective-cloning.aspx
java clone copy-constructor
Comments
Post a Comment