楼上的同学先看看API怎么说 别教错了
public class CloneNotSupportedException
extends Exception
Thrown to indicate that the clone method in class Object has been called to clone an object, but that the object's class does not implement the Cloneable interface.
Applications that override the clone method can also throw this exception to indicate that an object could not or should not be cloned.
然后写个例子看看:
public class Test {
public static void main(String[] args) throws Exception {
Test t = new Test();
Test t2 = null;
t2 = (Test) t.clone();
System.out.println(t2);
}
}
运行下看看结果如何
然后改一点点看:
public class Test implements Cloneable {
public static void main(String[] args) throws Exception {
Test t = new Test();
Test t2 = null;
t2 = (Test) t.clone();
System.out.println(t2);
}
}
这次又怎样?