嗨我在java中尝试深度克隆我想深度克隆这个类Deepcloning,它有两个原始字段和一个引用
public class Deepcloning implements Cloneable {
private String name;
private int age;
private Adress adress;
public Deepcloning() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Adress getAdress() {
return adress;
}
public void setAdress(Adress adress) {
this.adress = adress;
}
@Override
public Object clone() throws CloneNotSupportedException {
Deepcloning shls = (Deepcloning) super.clone();
shls.setAdress((Adress) adress.clone());
return shls;
}
}
我想克隆这个类但仍然得到错误,类型对象的方法克隆不可见错误。任何帮助将不胜感激