commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gregor Zeitlinger" <>
Subject [lang] Cloneable replacement/CloneBuilder
Date Sun, 29 Oct 2006 13:24:33 GMT
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.

I would welcome a utility class that assists in implementing clone:
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) {
    B other = (B) result;
    other.value = value;

The CloneBuilder would preferably make this simpler.

Gregor Zeitlinger

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message