Cloneable接口是Java开发中常用的一个接口, 它的作用是使一个类的实例能够将自身拷贝到另一个新的实例中,注意,这里所说的“拷贝”拷的是对象实例,而不是类的定义,进一步说,拷贝的是一个类的实例中各字段的值。
在开发过程中,拷贝实例是常见的一种操作,如果一个类中的字段较多,而我们又采用在客户端中逐字段复制的方法进行拷贝操作的话,将不可避免的造成客户端代码繁杂冗长,而且也无法对类中的私有成员进行复制,而如果让需要具备拷贝功能的类实现Cloneable接口,并重写clone()方法,就可以通过调用clone()方法的方式简洁地实现实例拷贝功能。
深拷贝(深复制)和浅拷贝(浅复制)是两个比较通用的概念,尤其在C++语言中,若不弄懂,则会在delete的时候出问题,但是我们在这幸好用的是Java。虽然Java自动管理对象的回收,但对于深拷贝(深复制)和浅拷贝(浅复制),我们还是要给予足够的重视,因为有时这两个概念往往会给我们带来不小的困惑。
浅拷贝是指拷贝对象时仅仅拷贝对象本身(包括对象中的基本变量),而不拷贝对象包含的引用指向的对象。深拷贝不仅拷贝对象本身,而且拷贝对象包含的引用指向的所有对象。举例来说更加清楚:对象 A1 中包含对 B1 的引用, B1 中包含对 C1 的引用。浅拷贝 A1 得到 A2 , A2 中依然包含对 B1 的引用, B1 中依然包含对 C1 的引用。
深拷贝则是对浅拷贝的递归,深拷贝 A1 得到 A2 , A2 中包含对 B2 ( B1 的 copy )的引用, B2 中包含对 C2 ( C1 的 copy )的引用。https://www.jianshu.com/p/c9d7a65451fc
https://www.jianshu.com/p/08b38d4fdf08
https://www.jianshu.com/p/21a41ef5677b
https://www.jianshu.com/p/0b36275a242a
https://www.jianshu.com/p/b3035cc157fa
https://www.jianshu.com/p/9120292fe000
https://www.jianshu.com/p/7d5a68c8ec9a
https://www.jianshu.com/p/d622e3aea9e1
https://www.jianshu.com/p/b6c090fbf3c7
https://www.jianshu.com/p/e55a66b72ab0
https://www.jianshu.com/p/1360e0a04926
https://www.jianshu.com/p/ad9ecb05c278
https://www.jianshu.com/p/14b2d8d25a13
https://www.jianshu.com/p/399d150aa640
https://www.jianshu.com/p/06c695065f39
https://www.jianshu.com/p/898743752411
https://www.jianshu.com/p/353df67af811
https://www.jianshu.com/p/50c50ba122f5
https://www.jianshu.com/p/d80e3ad1742c
https://www.jianshu.com/p/30126d7d0751
https://www.jianshu.com/p/42a52d1438a0
https://www.jianshu.com/p/923c922eef6f
https://www.jianshu.com/p/562971730827
https://www.jianshu.com/p/76b829a7b395
https://www.jianshu.com/p/103e42866da2
https://www.jianshu.com/p/a7559ff49e46
https://www.jianshu.com/p/68ad8ae403da
https://www.jianshu.com/p/955240b70de7
https://www.jianshu.com/p/5899d1f9d29a
https://www.jianshu.com/p/b60e0a550b6d
https://www.jianshu.com/p/fee6843699be
https://www.jianshu.com/p/9ed69777b56a
https://www.jianshu.com/p/608d9d12d0e5
https://www.jianshu.com/p/36dbb4855f0b
https://www.jianshu.com/p/5b078d5f383a
https://www.jianshu.com/p/814f70b753b9
https://www.jianshu.com/p/2704d6101780
https://www.jianshu.com/p/f67f82fb45a7
https://www.jianshu.com/p/9948c02f0b38
https://www.jianshu.com/p/e3d41231eb33
https://www.jianshu.com/p/c6c10c21a6b6
https://www.jianshu.com/p/169e132458c7
https://www.jianshu.com/p/76ba476104bb
https://www.jianshu.com/p/b81e72d3feff
https://www.jianshu.com/p/2a8b8c4a10a7
https://www.jianshu.com/p/bcc4b966a2f5
https://www.jianshu.com/p/c73890c5d4e0
https://www.jianshu.com/p/e348c09f12d2
https://www.jianshu.com/p/df06999ec7df
https://www.jianshu.com/p/c654d9d1abef
https://www.jianshu.com/p/578f5deedf16
https://www.jianshu.com/p/d94fa389cd35
https://www.jianshu.com/p/23f730e63a68
https://www.jianshu.com/p/f3b1b7a1d7a4
https://www.jianshu.com/p/9735fe514f1f
https://www.jianshu.com/p/c3106bb78115
https://www.jianshu.com/p/993ff622eb5f
https://www.jianshu.com/p/441bc5c5bc42
https://www.jianshu.com/p/f6a935cbd5ff
https://www.jianshu.com/p/ab3b22a4932a
https://www.jianshu.com/p/5ff38eb7ec55
https://www.jianshu.com/p/38875950d6d4
https://www.jianshu.com/p/65242310017d
https://www.jianshu.com/p/1ded4b378900
https://www.jianshu.com/p/5113f28590e4
https://www.jianshu.com/p/35cc5e93b7e9
https://www.jianshu.com/p/5886dfa07df2
https://www.jianshu.com/p/f56edd5196ac
https://www.jianshu.com/p/96af33a4e120
https://www.jianshu.com/p/2ce45f17f12d
https://www.jianshu.com/p/8bbdab128386
https://www.jianshu.com/p/2a2ea97eb01a
https://www.jianshu.com/p/e7bb26664b8c
https://www.jianshu.com/p/fa86081ad969
https://www.jianshu.com/p/527acc6300c7
https://www.jianshu.com/p/c4d10c5bbfee
https://www.jianshu.com/p/3f5057516b28
https://www.jianshu.com/p/8fe4c2b28664
https://www.jianshu.com/p/e8c7106a2d32
https://www.jianshu.com/p/3fbd868c48f9
https://www.jianshu.com/p/86f7ad1f1e47
https://www.jianshu.com/p/8088486da110
https://www.jianshu.com/p/036b3583352d
https://www.jianshu.com/p/1d4c25339500
https://www.jianshu.com/p/7b856eebfc5f
https://www.jianshu.com/p/8b9f564ec233
https://www.jianshu.com/p/c9a3c1b4be4a
https://www.jianshu.com/p/059ad3550f2b
https://www.jianshu.com/p/be453364b649
https://www.jianshu.com/p/e88d77932ba4
https://www.jianshu.com/p/9fab1678edc2
https://www.jianshu.com/p/c6259a3a98dc
https://www.jianshu.com/p/74f9fc3d763e
https://www.jianshu.com/p/16d538e447ed
https://www.jianshu.com/p/62028d26ab98
https://www.jianshu.com/p/1d5220e3801b
https://www.jianshu.com/p/8f8ad7f1a626
https://www.jianshu.com/p/3f69f7d1d956
https://www.jianshu.com/p/1434806a4c32
https://www.jianshu.com/p/fffe02a780ae
https://www.jianshu.com/p/cd1e744850d0
https://www.jianshu.com/p/d4b68f7b5028
https://www.jianshu.com/p/30c188251cf0
https://www.jianshu.com/p/8318dd35b24f
https://www.jianshu.com/p/aeda50d24fbf
https://www.jianshu.com/p/8e270da1d117
https://www.jianshu.com/p/8f66831f34db
https://www.jianshu.com/p/7f105500c452
https://www.jianshu.com/p/29ec7a12fc3b
https://www.jianshu.com/p/fd464598615e
https://www.jianshu.com/p/6d64e5589f72
https://www.jianshu.com/p/1ac3618d10a4
https://www.jianshu.com/p/292fedaca43f
https://www.jianshu.com/p/7de8dc29204f
https://www.jianshu.com/p/2aa2099a6c64
https://www.jianshu.com/p/5adeb7dd293e
https://www.jianshu.com/p/3941d9cbd96f
https://www.jianshu.com/p/611a612349a1
https://www.jianshu.com/p/b3c4c9c81828
https://www.jianshu.com/p/219da44c4f07
https://www.jianshu.com/p/77a8cfa5d158
https://www.jianshu.com/p/472f3ae70710
https://www.jianshu.com/p/d519fcd61d88
https://www.jianshu.com/p/7c92a4b43dfc
https://www.jianshu.com/p/008004f15aab
https://www.jianshu.com/p/371254c27d53
https://www.jianshu.com/p/819796a74a99
https://www.jianshu.com/p/20ff3cb82cd8
https://www.jianshu.com/p/398fde0feee4
https://www.jianshu.com/p/2bcc0d2dc473
https://www.jianshu.com/p/c0303f14ed32
https://www.jianshu.com/p/39b98ab7ead9
https://www.jianshu.com/p/26140612875a
https://www.jianshu.com/p/cf8f13c66548
https://www.jianshu.com/p/cd30cdabee1a
https://www.jianshu.com/p/98b24d60a71a
https://www.jianshu.com/p/a7941cf6c26e
https://www.jianshu.com/p/231ca0c57a91
https://www.jianshu.com/p/dcce2a660381
https://www.jianshu.com/p/886b709ff738
https://www.jianshu.com/p/ab11abc96666
https://www.jianshu.com/p/dc3292fff66d
https://www.jianshu.com/p/d1a729076aa4
https://www.jianshu.com/p/f7f2e87ab619
https://www.jianshu.com/p/65feff33b367
https://www.jianshu.com/p/bc0ea29ca8f8
https://www.jianshu.com/p/83ac5b38c049
https://www.jianshu.com/p/02a80e517173
https://www.jianshu.com/p/c935806240f0
https://www.jianshu.com/p/fd20f61b1a9a
https://www.jianshu.com/p/5b293b157d00
https://www.jianshu.com/p/cccf45e009c3
https://www.jianshu.com/p/b9f3cad8454b
https://www.jianshu.com/p/7203c28f4952
https://www.jianshu.com/p/1a957406f16a
https://www.jianshu.com/p/4391d2fad5c5
https://www.jianshu.com/p/1d9d1d8dfb97
https://www.jianshu.com/p/6f4c4fb90bb5
https://www.jianshu.com/p/fc0293c0c7af
https://www.jianshu.com/p/ebfd59ddd030
https://www.jianshu.com/p/fd0100110bb9
https://www.jianshu.com/p/354fd4cb81e3
https://www.jianshu.com/p/1392e5d98c7a
https://www.jianshu.com/p/c982fd5d0fc9
https://www.jianshu.com/p/44750c858285
https://www.jianshu.com/p/304993766c24
https://www.jianshu.com/p/e77a714db736
https://www.jianshu.com/p/e55c4b13d20e
https://www.jianshu.com/p/c2eb1569d76b
https://www.jianshu.com/p/0312d006b668
https://www.jianshu.com/p/e8b5dae888b4
https://www.jianshu.com/p/7d22b596d9bd
https://www.jianshu.com/p/c5bbc1da93cf
https://www.jianshu.com/p/88d0a3e37688
https://www.jianshu.com/p/210d89f317b0
https://www.jianshu.com/p/857e5bd4bd73
https://www.jianshu.com/p/7031e46eeaf2
https://www.jianshu.com/p/096475903564
https://www.jianshu.com/p/f8e698c3a016
https://www.jianshu.com/p/aa1bd1792cfb
https://www.jianshu.com/p/b9bddc770a05
https://www.jianshu.com/p/6c1b6acc3a45
https://www.jianshu.com/p/5bb05d6c5457
https://www.jianshu.com/p/22eee081dae3
https://www.jianshu.com/p/8100904dfdd0
https://www.jianshu.com/p/cd2e7bfb0ce2
https://www.jianshu.com/p/8c815cd264ce
https://www.jianshu.com/p/ecae63a58b7f
https://www.jianshu.com/p/c57dd879bee8
https://www.jianshu.com/p/cf1bdf31684c
https://www.jianshu.com/p/d457ade78a5f
https://www.jianshu.com/p/5ec661eb4061
https://www.jianshu.com/p/9c59aefcffa5
https://www.jianshu.com/p/e6ba39f085ce
https://www.jianshu.com/p/841d7e3ff465
https://www.jianshu.com/p/525a37f67a19
https://www.jianshu.com/p/e73c251a00b7
https://www.jianshu.com/p/239c7fa85da4
https://www.jianshu.com/p/ca90558d925a
https://www.jianshu.com/p/e6fc70984f1a
https://www.jianshu.com/p/42eb477b9f79
https://www.jianshu.com/p/b6a29e105f6b
https://www.jianshu.com/p/3891327e39be
https://www.jianshu.com/p/df244d46fe67
https://www.jianshu.com/p/5350e5e4051d
https://www.jianshu.com/p/52d15d5d6666
https://www.jianshu.com/p/727f191983d6
https://www.jianshu.com/p/121ff6d6d493
https://www.jianshu.com/p/1331d0d5e82f
https://www.jianshu.com/p/c7050fbdb3e7
https://www.jianshu.com/p/d2abe2df1248
https://www.jianshu.com/p/ddeadc02d5ac
https://www.jianshu.com/p/c5587f340ebd
https://www.jianshu.com/p/2eb9116df5cc
https://www.jianshu.com/p/d16968f4601d
https://www.jianshu.com/p/f00897a39c45
https://www.jianshu.com/p/398b6feba14b
https://www.jianshu.com/p/c2ab0148b13a
https://www.jianshu.com/p/da339120c0ac
https://www.jianshu.com/p/cfdf578f7343
https://www.jianshu.com/p/7f749c8a3f65
https://www.jianshu.com/p/0cb184b25a67
https://www.jianshu.com/p/17a19013e66b
https://www.jianshu.com/p/b53e3177715a
https://www.jianshu.com/p/3829582693b3
https://www.jianshu.com/p/826ee7d6f9b2
https://www.jianshu.com/p/1c7027c00916
https://www.jianshu.com/p/427b3fff9a46
https://www.jianshu.com/p/6a0c7e2aeb76
https://www.jianshu.com/p/a2a51d746362
https://www.jianshu.com/p/7a80760e14c6
https://www.jianshu.com/p/5b2e524212c5
https://www.jianshu.com/p/17f5d06f0c3a
https://www.jianshu.com/p/4ae9b0780c14
https://www.jianshu.com/p/2c5b5d2721a4
https://www.jianshu.com/p/f0191ef4f4fe
https://www.jianshu.com/p/d07ba71165e1
https://www.jianshu.com/p/f55137001760
https://www.jianshu.com/p/da691de76ff1
https://www.jianshu.com/p/a343bcee1985
https://www.jianshu.com/p/ea86df410591
https://www.jianshu.com/p/d1d815d68af5
https://www.jianshu.com/p/67b61066f559
https://www.jianshu.com/p/70a12d3d877a
https://www.jianshu.com/p/8e469999c957
https://www.jianshu.com/p/9bdd5cd9610e
https://www.jianshu.com/p/8105b0719218
https://www.jianshu.com/p/091a49bff345
https://www.jianshu.com/p/4ce72f65a706
https://www.jianshu.com/p/09694b8164b4
https://www.jianshu.com/p/21ad94b967b6
https://www.jianshu.com/p/724015951729
https://www.jianshu.com/p/30393b587767
https://www.jianshu.com/p/e134981b54e6
https://www.jianshu.com/p/75e2a282268a
https://www.jianshu.com/p/25bb8b0979dd
https://www.jianshu.com/p/084bbb0e8718
https://www.jianshu.com/p/63c19f3bc557
https://www.jianshu.com/p/57ed357675b0
https://www.jianshu.com/p/81da2403bf04
https://www.jianshu.com/p/4261d553af29
https://www.jianshu.com/p/9adfca79034e
https://www.jianshu.com/p/c63f5427ff67
https://www.jianshu.com/p/07f8388b64e4
https://www.jianshu.com/p/4b6d6e821487
https://www.jianshu.com/p/911be9d5361e
https://www.jianshu.com/p/72c5b559e2f4
https://www.jianshu.com/p/e009cba44d41
https://www.jianshu.com/p/e78f00bb54d4
https://www.jianshu.com/p/a66fd16ec94a
https://www.jianshu.com/p/ddb15bca024a
https://www.jianshu.com/p/edbde9a70eb8
https://www.jianshu.com/p/385e0edd2bf3
https://www.jianshu.com/p/8d6a1378abbe
https://www.jianshu.com/p/c6e99a972381
https://www.jianshu.com/p/c359a1d503d1
https://www.jianshu.com/p/81d858a9ee0a
https://www.jianshu.com/p/d7bbbeb16fae
https://www.jianshu.com/p/8f41bcac23b5
https://www.jianshu.com/p/35284d2c4e4f
https://www.jianshu.com/p/737691a58503
https://www.jianshu.com/p/314dcd017fa8
https://www.jianshu.com/p/03b8da8230cf
https://www.jianshu.com/p/7a4acb638a9d
https://www.jianshu.com/p/928114eef9f3
https://www.jianshu.com/p/653154dfdb57
https://www.jianshu.com/p/798df5a0fc60
https://www.jianshu.com/p/1e4f43308635
https://www.jianshu.com/p/92f8e3c0f1b1
https://www.jianshu.com/p/df058825e362
https://www.jianshu.com/p/38da6031552f
https://www.jianshu.com/p/7fb89235481d
https://www.jianshu.com/p/7e592997be8b
https://www.jianshu.com/p/dae5f051bdd7
https://www.jianshu.com/p/ecdbea938391
https://www.jianshu.com/p/15eb32dea59c
https://www.jianshu.com/p/d6ed6449f315
https://www.jianshu.com/p/8c50a4233c8f
https://www.jianshu.com/p/5b219e9b7dc9
https://www.jianshu.com/p/896ce8e104d3
https://www.jianshu.com/p/f5d30593e7df
https://www.jianshu.com/p/45a4dc00bb94
https://www.jianshu.com/p/f14a762bdf42
https://www.jianshu.com/p/28dcc04d584a
https://www.jianshu.com/p/6df543332e77
https://www.jianshu.com/p/4517c54f85a3
https://www.jianshu.com/p/0f0561b16e93
https://www.jianshu.com/p/537fa7bc7898
https://www.jianshu.com/p/d5336e67e9b5
https://www.jianshu.com/p/89c708c337ea
https://www.jianshu.com/p/eead10bc55e7
https://www.jianshu.com/p/5c7c530510b3
https://www.jianshu.com/p/7293d9d53754
https://www.jianshu.com/p/e6760a8dff0c
https://www.jianshu.com/p/fe4822496c6b
https://www.jianshu.com/p/b56e6b1d7345
https://www.jianshu.com/p/b1a337e3f5e3
https://www.jianshu.com/p/d1f43299bf55
https://www.jianshu.com/p/e80d3c535829
https://www.jianshu.com/p/79d4137b06b4
https://www.jianshu.com/p/9e9dec425a1a
https://www.jianshu.com/p/7d7e17db9bd8
https://www.jianshu.com/p/7f65fc43ea00
https://www.jianshu.com/p/874ee84d8a2c
https://www.jianshu.com/p/acf8c814e0bb
https://www.jianshu.com/p/604e526d8ed3
https://www.jianshu.com/p/300f368baeb6
https://www.jianshu.com/p/a4e5d819cc29
https://www.jianshu.com/p/2349ad59201b
https://www.jianshu.com/p/2a4f2d75f6f2
https://www.jianshu.com/p/27a773c2c92d
https://www.jianshu.com/p/446673a61a45
https://www.jianshu.com/p/64060cc1ca3b
https://www.jianshu.com/p/97df17591ad4
https://www.jianshu.com/p/c8852296fe2e
https://www.jianshu.com/p/e9e41137a480
https://www.jianshu.com/p/f6c2a616c4f4
https://www.jianshu.com/p/d348a6d4428a
https://www.jianshu.com/p/e10d2113b8f0
https://www.jianshu.com/p/bc43ac738c2b
https://www.jianshu.com/p/66a6e0d1a9e7
https://www.jianshu.com/p/cc016d892641
https://www.jianshu.com/p/7247d9711170
https://www.jianshu.com/p/12a6ed5f57f1
https://www.jianshu.com/p/bdeb677e6654
https://www.jianshu.com/p/db4cc6286e70
https://www.jianshu.com/p/c933c3a81bab
https://www.jianshu.com/p/ba201654a2e0
https://www.jianshu.com/p/7391c62ca7b8
https://www.jianshu.com/p/f04e92abb681
https://www.jianshu.com/p/d9667349784a
https://www.jianshu.com/p/883522e1c3bc
https://www.jianshu.com/p/ceb66a9a6410
https://www.jianshu.com/p/88d3c0a67412
https://www.jianshu.com/p/0c9f0a70bac9
https://www.jianshu.com/p/31e7350d6f15
https://www.jianshu.com/p/0283997df5d7
https://www.jianshu.com/p/68450006df3a
https://www.jianshu.com/p/5e9bcb0c4edd
https://www.jianshu.com/p/d1693534f548
https://www.jianshu.com/p/c9ae187d079a
https://www.jianshu.com/p/c633e26eadca
https://www.jianshu.com/p/bf16cbf14a0b
https://www.jianshu.com/p/2a7d1032634b
https://www.jianshu.com/p/8589d94cba61
https://www.jianshu.com/p/59800d93ddbc
https://www.jianshu.com/p/645d6fb3fe0c