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

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -