{"id":18909,"date":"2025-08-07T21:54:35","date_gmt":"2025-08-07T13:54:35","guid":{"rendered":"https:\/\/92it.top\/?p=18909"},"modified":"2025-08-07T21:54:35","modified_gmt":"2025-08-07T13:54:35","slug":"%e6%b7%b1%e6%8b%b7%e8%b4%9d%e6%b5%85%e6%8b%b7%e8%b4%9d%ef%bc%8c%e4%b8%80%e4%b8%aa%e4%be%8b%e5%ad%90%e5%b0%b1%e6%98%8e%e7%99%bd","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=18909","title":{"rendered":"\u6df1\u62f7\u8d1d\u6d45\u62f7\u8d1d\uff0c\u4e00\u4e2a\u4f8b\u5b50\u5c31\u660e\u767d"},"content":{"rendered":"\n<p>\u8f6c\u8f7d\uff1a<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzUyMzkwNjIzNg==&amp;mid=2247484033&amp;idx=1&amp;sn=74cfdb22666b5c84595398c811b5b096&amp;chksm=fba9fdc3e4e05267acb957582171fbf4ad97f19af0b55984021c75fa6cafc1c9ff5b25c099ff&amp;mpshare=1&amp;scene=1&amp;srcid=0807C37yfhGkwKkkZDpWU2ns&amp;sharer_shareinfo=853b4f344eeeaa42ab3cbea04508d4aa&amp;sharer_shareinfo_first=0607ec7b248ad9551e46880075141acf&amp;exportkey=n_ChQIAhIQn4JTB9hwR4eOhXpw6%2BDf0BL0AQIE97dBBAEAAAAAAJhHKrb1UykAAAAOpnltbLcz9gKNyK89dVj0YvYOWASHLACw0Jvs8Ht91HYzCNZhpwbRzvmgVQoYT8UNT3aR1slfsfiDKiZfccVSu27XZtK7BgOypG3Wy1yWGRGuIXAkRWyjaLyQpHf1fbPzvGiLUeXkAVMUP8KChtUdiJFJ00I5PK8XuxxHkO45F5INMUdolGP2IHONQV1qiWtYIk%2Bs2f8BzJHZXzff9C4qDp9DX5hk3w7tHl7wn%2BjIiNPK7eEzWFKSsN9BAXDsrgAy6rAntzGc3tjst5LCdBInPquoZqr%2FHhcOuJDaBcU%3D&amp;acctmode=0&amp;pass_ticket=XPygcdQpYlTAqVS%2BdA7bdFNEd8o3norXY300r94Y%2FCpY00u3EGD%2FSIAj%2FFH7XqRo&amp;wx_header=0#rd\">\u6df1\u62f7\u8d1d\u6d45\u62f7\u8d1d\uff0c\u4e00\u4e2a\u4f8b\u5b50\u5c31\u660e\u767d<\/a><\/p>\n\n\n\n<p>\u4eca\u5929\u5206\u4eab\u4e00\u4e2aJava\u5f00\u53d1\u4e2d\u7ecf\u5e38\u9047\u5230\u7684\u95ee\u9898\uff1a\u62f7\u8d1d\u5bf9\u8c61\u65f6\uff0c\u6709\u65f6\u5019\u6539\u4e86\u4e00\u4e2a\u5bf9\u8c61\uff0c\u53e6\u4e00\u4e2a\u5bf9\u8c61\u4e5f\u8ddf\u7740\u53d8\u4e86\u3002\u8fd9\u662f\u600e\u4e48\u56de\u4e8b\u5462\uff1f<\/p>\n\n\n\n<p>\u5176\u5b9e\u8fd9\u6d89\u53ca\u5230\u62f7\u8d1d\u7684\u4e24\u79cd\u65b9\u5f0f\uff1a<strong>\u6d45\u62f7\u8d1d<\/strong>\u548c<strong>\u6df1\u62f7\u8d1d<\/strong>\u3002\u522b\u88ab\u540d\u5b57\u5413\u5230\uff0c\u4e00\u4e2a\u4f8b\u5b50\u5c31\u80fd\u641e\u61c2\uff01<\/p>\n\n\n\n<p><strong>\u4ec0\u4e48\u662f\u6d45\u62f7\u8d1d\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u53ea\u590d\u5236\u5bf9\u8c61\u7684\u8868\u9762\uff0c\u5185\u90e8\u5f15\u7528\u8fd8\u662f\u5171\u4eab\u7684<\/p>\n\n\n\n<p>\u6211\u4eec\u5148\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public classStudent {\n    private String name;\n    private List&lt;String> hobbies;\n    \n    \/\/ \u6784\u9020\u65b9\u6cd5\u3001getter\u3001setter\u7701\u7565...\n    \n    \/\/ \u6d45\u62f7\u8d1d\u65b9\u6cd5\n    public Student shallowCopy() {\n        Studentcopy=newStudent();\n        copy.name = this.name;\n        copy.hobbies = this.hobbies; \/\/ \u76f4\u63a5\u8d4b\u503c\u5f15\u7528\n        return copy;\n    }\n}<\/pre>\n\n\n\n<p>\u6d4b\u8bd5\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public classTest {\n    publicstaticvoidmain(String[] args) {\n        Studentstudent1=newStudent();\n        student1.setName(\"\u5c0f\u660e\");\n        student1.setHobbies(Arrays.asList(\"\u7bee\u7403\", \"\u6e38\u620f\"));\n        \n        \/\/ \u6d45\u62f7\u8d1d\n        Studentstudent2= student1.shallowCopy();\n        \n        \/\/ \u4fee\u6539student2\u7684\u7231\u597d\n        student2.getHobbies().add(\"\u7f16\u7a0b\");\n        \n        System.out.println(\"student1\u7684\u7231\u597d\uff1a\" + student1.getHobbies());\n        System.out.println(\"student2\u7684\u7231\u597d\uff1a\" + student2.getHobbies());\n    }\n}<\/pre>\n\n\n\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">student1\u7684\u7231\u597d\uff1a[\u7bee\u7403, \u6e38\u620f, \u7f16\u7a0b]\nstudent2\u7684\u7231\u597d\uff1a[\u7bee\u7403, \u6e38\u620f, \u7f16\u7a0b]<\/pre>\n\n\n\n<p>\u770b\u5230\u4e86\u5417\uff1f\u6211\u4eec\u53ea\u4fee\u6539\u4e86student2\uff0c\u4f46student1\u4e5f\u8ddf\u7740\u53d8\u4e86\uff01\u8fd9\u5c31\u662f\u6d45\u62f7\u8d1d\u7684\u7279\u70b9\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4ec0\u4e48\u662f\u6df1\u62f7\u8d1d\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u4e0d\u4ec5\u590d\u5236\u5bf9\u8c61\u8868\u9762\uff0c\u8fde\u5185\u90e8\u7684\u5f15\u7528\u5bf9\u8c61\u4e5f\u91cd\u65b0\u521b\u5efa<\/p>\n\n\n\n<p>\u518d\u770b\u6df1\u62f7\u8d1d\u7684\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public classStudent {\n    private String name;\n    private List&lt;String> hobbies;\n    \n    \/\/ \u6df1\u62f7\u8d1d\u65b9\u6cd5\n    public Student deepCopy() {\n        Studentcopy=newStudent();\n        copy.name = this.name;\n        copy.hobbies = newArrayList&lt;>(this.hobbies); \/\/ \u521b\u5efa\u65b0\u7684List\n        return copy;\n    }\n}<\/pre>\n\n\n\n<p>\u6d4b\u8bd5\u6df1\u62f7\u8d1d\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public classTest {\n    publicstaticvoidmain(String[] args) {\n        Studentstudent1=newStudent();\n        student1.setName(\"\u5c0f\u660e\");\n        student1.setHobbies(Arrays.asList(\"\u7bee\u7403\", \"\u6e38\u620f\"));\n        \n        \/\/ \u6df1\u62f7\u8d1d\n        Studentstudent3= student1.deepCopy();\n        \n        \/\/ \u4fee\u6539student3\u7684\u7231\u597d\n        student3.getHobbies().add(\"\u7f16\u7a0b\");\n        \n        System.out.println(\"student1\u7684\u7231\u597d\uff1a\" + student1.getHobbies());\n        System.out.println(\"student3\u7684\u7231\u597d\uff1a\" + student3.getHobbies());\n    }\n}<\/pre>\n\n\n\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">student1\u7684\u7231\u597d\uff1a[\u7bee\u7403, \u6e38\u620f]\nstudent3\u7684\u7231\u597d\uff1a[\u7bee\u7403, \u6e38\u620f, \u7f16\u7a0b]<\/pre>\n\n\n\n<p>\u8fd9\u6b21student1\u6ca1\u6709\u53d7\u5230\u5f71\u54cd\uff0c\u8fd9\u5c31\u662f\u6df1\u62f7\u8d1d\u7684\u6548\u679c\uff01<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e24\u8005\u533a\u522b\u4e00\u76ee\u4e86\u7136<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u901a\u8fc7\u5185\u5b58\u7ed3\u6784\u56fe\u7406\u89e3\u672c\u8d28\u5dee\u5f02<\/p>\n\n\n\n<p>\u8ba9\u6211\u4eec\u7528\u56fe\u6765\u770b\u770b\u5185\u5b58\u4e2d\u53d1\u751f\u4e86\u4ec0\u4e48\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"279\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/08\/image-205-1024x279.png\" alt=\"\" class=\"wp-image-18910\" style=\"width:480px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/08\/image-205-1024x279.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/08\/image-205-300x82.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/08\/image-205-768x209.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/08\/image-205-830x226.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/08\/image-205-230x63.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/08\/image-205-350x95.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/08\/image-205-480x131.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/08\/image-205.png 1050w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>\u6d45\u62f7\u8d1d\u7684\u95ee\u9898<\/strong>\uff1a\u4e24\u4e2a\u5bf9\u8c61\u7684hobbies\u5f15\u7528\u6307\u5411\u540c\u4e00\u4e2aList\uff0c\u4fee\u6539\u4efb\u4f55\u4e00\u4e2a\u90fd\u4f1a\u5f71\u54cd\u53e6\u4e00\u4e2a\u3002<\/p>\n\n\n\n<p><strong>\u6df1\u62f7\u8d1d\u7684\u4f18\u52bf<\/strong>\uff1a\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u81ea\u5df1\u72ec\u7acb\u7684List\uff0c\u4e92\u4e0d\u5f71\u54cd\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u5f00\u53d1\u4e2d\u7684\u5b9e\u9645\u5e94\u7528<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u77e5\u9053\u4ec0\u4e48\u65f6\u5019\u8be5\u7528\u54ea\u79cd\u62f7\u8d1d<\/p>\n\n\n\n<p><strong>1. \u914d\u7f6e\u5bf9\u8c61\u62f7\u8d1d<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u7cfb\u7edf\u914d\u7f6e\u9700\u8981\u6df1\u62f7\u8d1d\uff0c\u907f\u514d\u8bef\u4fee\u6539\u5f71\u54cd\u5168\u5c40\nSystemConfig backupConfig = originalConfig.deepCopy();<\/pre>\n\n\n\n<p><strong>2. \u7f13\u5b58\u6570\u636e\u62f7\u8d1d<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u4ece\u7f13\u5b58\u53d6\u51fa\u7684\u5bf9\u8c61\u8981\u6df1\u62f7\u8d1d\uff0c\u907f\u514d\u4e1a\u52a1\u4fee\u6539\u6c61\u67d3\u7f13\u5b58\nUser userFromCache = cache.get(userId).deepCopy();<\/pre>\n\n\n\n<p><strong>3. \u4ec0\u4e48\u65f6\u5019\u7528\u6d45\u62f7\u8d1d<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u53ea\u662f\u60f3\u590d\u5236\u57fa\u672c\u5c5e\u6027\uff0c\u5185\u90e8\u5bf9\u8c61\u672c\u8eab\u5c31\u662f\u4e0d\u53ef\u53d8\u7684\nStudent student = original.shallowCopy(); \/\/ String\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u53ef\u4ee5\u653e\u5fc3\u6d45\u62f7\u8d1d\n<\/pre>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u5b9e\u73b0\u6df1\u62f7\u8d1d\u7684\u5e38\u7528\u65b9\u6cd5<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u4e09\u79cd\u65b9\u5f0f\uff0c\u5404\u6709\u7279\u70b9<\/p>\n\n\n\n<p><strong>\u65b9\u6cd5\u4e00\uff1a\u624b\u52a8\u5b9e\u73b0<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public Student deepCopy() {\n    Student copy = new Student();\n    copy.name = this.name;\n    copy.hobbies = new ArrayList&lt;>(this.hobbies);\n    return copy;\n}<\/pre>\n\n\n\n<p><strong>\u65b9\u6cd5\u4e8c\uff1a\u4f7f\u7528\u5e8f\u5217\u5316<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u9700\u8981\u5b9e\u73b0Serializable\u63a5\u53e3\npublic Student deepCopy()throws Exception {\n    ByteArrayOutputStreambos=newByteArrayOutputStream();\n    ObjectOutputStreamoos=newObjectOutputStream(bos);\n    oos.writeObject(this);\n    \n    ByteArrayInputStreambis=newByteArrayInputStream(bos.toByteArray());\n    ObjectInputStreamois=newObjectInputStream(bis);\n    return (Student) ois.readObject();\n}<\/pre>\n\n\n\n<p><strong>\u65b9\u6cd5\u4e09\uff1a\u4f7f\u7528\u5de5\u5177\u5e93<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u4f7f\u7528Apache Commons Lang\nStudent copy = SerializationUtils.clone(original);\n\n\/\/ \u4f7f\u7528JSON\u8f6c\u6362\uff08\u9700\u8981Gson\u7b49\u5e93\uff09\nString json = gson.toJson(original);\nStudent copy = gson.fromJson(json, Student.class);<\/pre>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u8bb0\u4f4f\u8fd9\u4e2a\u53e3\u8bc0\uff1a<\/p>\n\n\n\n<ul>\n<li>\u2022\u00a0<strong>\u6d45\u62f7\u8d1d<\/strong>\uff1a\u8868\u9762\u5144\u5f1f\uff0c\u5185\u5fc3\u76f8\u901a<\/li>\n\n\n\n<li>\u2022\u00a0<strong>\u6df1\u62f7\u8d1d<\/strong>\uff1a\u72ec\u7acb\u4e2a\u4f53\uff0c\u5404\u81ea\u7cbe\u5f69<\/li>\n<\/ul>\n\n\n\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u6211\u4eec\u9700\u8981\u7684\u662f\u6df1\u62f7\u8d1d\uff0c\u7279\u522b\u662f\u6d89\u53ca\u5230\u96c6\u5408\u3001\u6570\u7ec4\u7b49\u5f15\u7528\u7c7b\u578b\u7684\u65f6\u5019\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1a\u6df1\u62f7\u8d1d\u6d45\u62f7\u8d1d\uff0c\u4e00\u4e2a\u4f8b\u5b50\u5c31\u660e\u767d \u4eca\u5929\u5206\u4eab\u4e00\u4e2aJava\u5f00\u53d1\u4e2d\u7ecf\u5e38\u9047\u5230\u7684\u95ee\u9898\uff1a\u62f7\u8d1d\u5bf9\u8c61\u65f6\uff0c\u6709\u65f6\u5019\u6539\u4e86\u4e00\u4e2a\u5bf9\u8c61\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/18909"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18909"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/18909\/revisions"}],"predecessor-version":[{"id":18911,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/18909\/revisions\/18911"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}