Clone基本知识储备
在Java里提到clone技术,就不能不提java.lang.Cloneable接口和含有clone方法的Object类。所有具有clone功能的类都有一个特性,那就是它直接或间接地实现了Cloneable接口。否则,我们在尝试调用clone()方法时,将会触发CloneNotSupportedException异常。下面我们通过对Object类的部分源码的分析,来发现和理解这一特性。请看JDK中Object# clone()方法的源码:
/*
…………
* @return a clone of this instance.
* @exception? CloneNotSupportedException? if the object''s class does not
*support the Cloneable interface. Subclasses
*that override the clone method can also
* throw this exception to i...[ 查看全文 ]