Connecting Tech Pros Worldwide Forums | Help | Site Map

The meaning of clone.

Boris Tkachenko
Guest
 
Posts: n/a
#1: Jun 27 '08

Hello, I was puzzled why the several guides and Java tutorials when
describing
the "Object clone();" method do not advice implementing clone using "new"

in my opinion standard implementation of clone should look like the
following.

public class MyClass implements Cloneable { ....

...

Myclass( Myclass x ) {
// copy constructor deep copy
...
}

Object clone() {
return new Myclass( this );
}

...

}

I wonder if anybody out there (Ghosling or whoever can tell me why is this
wrong").

Thanks
--

Boris Tkachenko
Yet another Java programmer.







Closed Thread