How to pass parameter in Object's clone function in Java -
all:
i wondering if define class implements 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(); } } i wonder how can give name new clone object?
thanks
make clone method yourself:
public object clone() throws clonenotsupportedexception { return new cloneobj(name); } edit
if want call super.clone();
public object clone() throws clonenotsupportedexception { cloneobj cloned = (cloneobj)super.clone(); cloned.name=this.name; //maybe (string)this.name.clone(); used return cloned; }
Comments
Post a Comment