参考copy链接:http://blog.csdn.net/bigconvience/article/details/25025561
在看原型模式,发现要用到clone这个方法,以前和朋友聊过,没怎么看过,刚好要用,就看看了。
源码解释:
/*** Creates and returns a copy of this object. The precise meaning
* of "copy" may depend on the class of the object. The general
* intent is that, for any object {@codex}, the expression:
*
*
* x.clone() != x
* will be true, and that the expression:
*
*
* x.clone().getClass() == x.getClass()
* will be {@codetrue}, but these are not absolute requirements.
* While it is typically the case that:
*
*
* x.clone().equals(x)
* will be {@codetrue}, this is not an absolute requirement.
*
* By convention, the returned object should be obtained by calling
* {@codesuper.clone}. If a class and all of its superclasses (except
* {@codeObject}) obey this convention, it will be the case that
* {@codex.clone().getClass() == x.getClass()}.
*
* By convention, the object returned by this method should be independent
* of this object (which is being cloned). To achieve this independence,
* it may be necessary to modify one or more fields of the object returned
* by {@codesuper.clone} before returning it. Typically, this means
* copying any mutable objects that comprise the internal "deep structure"
* of the object being cloned and replacing the references to these
* objects with references to the copies. If a class contains only
* primitive fields or references to immutable objects, then it is usually
* the case that no fields in the object returned by {@codesuper.clone}
* need to be modified.
*
* The method {@codeclone} for class {@codeObject} performs a
* specific cloning operation. First, if the class of this object does
* not implement the interface {@codeCloneable}, then a
* {@codeCloneNotSupportedException} is thrown. Note that all arrays
* are considered to implement the interface {@codeCloneable} and that
* the return type of the {@codeclone} method of an array type {@codeT[]}
* is {&#