Java 如何在 Object 的克隆函数中传递参数

How to pass parameter in Object's clone function in Java

全部:

我想知道我是否定义了一个 class 实现 Clonenble:

public class cloneobj implements Cloneable {
    String name;
    public cloneobj (String name){
        this.name = name;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        // TODO Auto-generated method stub
        return super.clone();
    }

}

我想知道如何给新的克隆对象命名?

谢谢

自己制作克隆方法:

public Object clone() throws CloneNotSupportedException {
    return new cloneobj(name);
}

编辑

如果你想打电话给super.clone();

public Object clone() throws CloneNotSupportedException {
    cloneobj cloned = (cloneobj)super.clone();
    cloned.name=this.name; //maybe (String)this.name.clone(); could be used
    return cloned;
}