#注意这里的区别实现深复制,浅复制的方式和区别,同时还可以通过对象序列化的方式实现深复制
class Protype implements Cloneable{
private int age;
private String name;
public Protype(String name,int age){
this.name=name;
this.age=age;
}
//getter and setter method
@Override
public Object clone(){
try {
Protype protype=(Protype)super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args){
Protype protype=new Protype("liurong",24);
Protype protype1=(Protype)protype.clone();
protype.name="wangliu";
System.out.println(protype.name); //输出为wangliu;
}
}
原型设计模式
最新推荐文章于 2025-12-05 17:02:52 发布
1264

被折叠的 条评论
为什么被折叠?



