1)
Since Cloneable is broken in Java, I think it would be a good idea to
introduce a better solution. The simplest solution would be

public interface Copyable extends Cloneable {
 public Object clone();
}

This would get rid of the problem that the clone method is not part of
the Cloneable interface.

I doesn't solve the problem that it would be nice to require that the
cloned object is exactly the same type:

public this clone();

but this isn't possible in Java.

2)
I would welcome a utility class that assists in implementing clone:
CloneBuilder
I don't really know the best way to do this, but it is important to
keep inheritance in mind.

public interface Copyable extends Cloneable {
 public Object clone();
 public Object clone(Object result);
}

public class A implements Copyable {
..
}
public class B extends A {
 int value;

 public Object clone() {
   return clone(new B());
 }
 public Object clone(Object result) {
   super.clone(result);
   B other = (B) result;
   other.value = value;
 }
}

The CloneBuilder would preferably make this simpler.

--
Gregor Zeitlinger
[EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to