「Java入門」cloneメソッドの使い方
説明
1.Cloneableインターフェイスを実施していないインスタンスを複製する場合、CloneNotSupportedExceptionが出力される
2.戻り値はObject型
サンプルコード
public class UserExample implements Cloneable {
protected String userId;
private int age;
public UserExample clone() {
try {
return (UserExample)super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError(e.toString());
}
}
}
public class UserExample implements Cloneable {
protected String userId;
private int age;
public UserExample clone() {
try {
return (UserExample)super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError(e.toString());
}
}
}
public class UserExample implements Cloneable { protected String userId; private int age; public UserExample clone() { try { return (UserExample)super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(e.toString()); } } }