package test;
import java.util.Iterator;
import java.util.Vector;
class AA implements Cloneable{
int a;
BB d = new BB(2021);
AA(int a){
this.a = a;
}
@Override
protected Object clone() throws CloneNotSupportedException {
AA temp = (AA)super.clone();
temp.d = (BB)this.d.clone();
return temp;
}
}
class BB implements Cloneable{
int a;
BB(int a){
this.a = a;
}
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
public class Vector_test {
public static void main(String[] args) {
Vector<Integer> vec = new Vector<Integer>();
vec.add(202);
vec.add(10);
Vector<Integer> vec1 = (Vector<Integer>)vec.clone();
vec1.set(0, 9);
for(int v : vec1)
System.out.println(v);
AA prio = new AA(2020);
System.out.println(prio.d);
try {
AA save = (AA)prio.clone();
System.out.println(save.d);
} catch (CloneNotSupportedException e) {
System.out.println("Exception!");
e.printStackTrace();
}
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-51258.html