| Emmanuel Lecharny 2007-10-27, 7:11 pm |
| David Jencks wrote:
>
> On Oct 27, 2007, at 11:56 AM, Alex Karasulu wrote:
>
>
> I doubt I have a clearer understanding but Joshua Bloch's Effective
> Java has 8 pages pointing out how hard it is to write clone methods
> correctly and the problems they cause and how copy constructors or
> factory methods have much clearer semantics and implementations. I
> never feel like I know what is going to happen when I call clone :-)
Beside being the worst episode of Star Wars, I wouls say that clone is
not my favorite Java feature, but I used it a couple of times without
problems. The rules I have adopted were pretty simple : if it start to
be complex, stop using clone... In fact, when it's strait forward, like
you have a flat object, or a very simple inheritance scheme, clone() is
an option. Otherwise, a good factory or copy() constructor is the way to
go.
When performance is an issue, then clone may become a candidate, but
with a lot of caution...
E.clone() (or is it E.clown() ? ;)
|