笔筒,黑客天下,异界之华山弟子
自己实现了一遍:
a() {
str = new string[2];
}
public object clone() {
a o = null;
try {
o = (a) super.clone();
} catch (clonenotsupportedexception e) {
e.printstacktrace();
}
o.str = new string[2];
return o;
}
}
void run() throws exception {
a a1 = new a(), a2 = new a();
a1.str[0] = "a"; a1.str[1] = "b";
a2 = (a) a1.clone();
a2.str[0] = "c"; a2.str[1] = "d";
system.out.println(a1.str[0] + " " + a2.str[0]);
}
结果:
a c
1.
public object clone() {
a o = null;
try {
o = (a) super.clone();
} catch (clonenotsupportedexception e) {
e.printstacktrace();
}
return o;
}
}
2.
public object clone() {
a o = null;
try {
o = (a) super.clone();
} catch (clonenotsupportedexception e) {
e.printstacktrace();
}
return o;
}
}
3.
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论