Principles If you override the clone method in a nonfinal class, you should return an object obtained by invoking super.clone In practice, a class that implements Cloneable is expected to provide a properly functioning public clone method. Never make…
Hi guys, I am happy to tell you that I am moving to the open source world. And Java is the 1st language I have chosen for this migration. It's a nice chance to read some great books like "Effective Java 2nd Edition" and share the note for what I…
1.进行浅拷贝时,只是复制原始数据类型的值,则可以通过覆盖Clone方法来达到.另外,在进行浅拷贝的时候,还要注意,成员对象中不应该要有引用类型,如果有引用类型,那么,进行了浅拷贝之后,两个对象将会共享成员引用所指向的对象,这会出现问题.所以,在这种情况下,干脆直接使用深拷贝,避免问题出现.2.对于深拷贝,也就是完全将对象的内容复制一份,则使用序列化来实现,也是为了避免覆盖Clone. 浅拷贝的例子: 这个例子,只是复制成员的值,成员的类型都是原始数据类型,不包含引用类型: public c…