{"id":4442,"date":"2019-07-31T14:56:27","date_gmt":"2019-07-31T06:56:27","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=4442"},"modified":"2019-07-31T14:56:27","modified_gmt":"2019-07-31T06:56:27","slug":"%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e7%b3%bb%e5%88%97%ef%bc%8c%e5%8e%9f%e5%9e%8b%e6%a8%a1%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4442","title":{"rendered":"\u8bbe\u8ba1\u6a21\u5f0f\u7cfb\u5217\uff0c\u539f\u578b\u6a21\u5f0f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u9762\u8bd5\u4e2d\uff0c\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u6e90\u7801\u3001\u6570\u636e\u7ed3\u6784\u3001\u6846\u67b6\u539f\u7406\u3001JVM\u3001GC\u3001\u4e2d\u95f4\u4ef6\u7b49\u4e00\u4e2a\u4e5f\u5c11\u4e0d\u4e86\uff0c\u6240\u6709\u7684\u8fd9\u4e9b\u4e1c\u897f\u90fd\u9700\u8981\u5e73\u65f6\u8fdb\u884c\u79ef\u7d2f\u3002\u6211\u8fd9\u91cc\u540e\u9762\u4f1a\u505a\u4e00\u4e2a\u4e13\u9898\uff0c\u628a\u8bbe\u8ba1\u6a21\u5f0f\u5355\u72ec\u505a\u6210\u4e00\u4e2a\u83dc\u5355\uff0c\u65b9\u4fbf\u540e\u9762\u9762\u8bd5\u7684\u5404\u4f4d\u7f51\u53cb\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcly1g5j0uedcd6j20py0rstal.jpg\" alt=\"\" \/><figcaption>\u8bbe\u8ba1\u6a21\u5f0f\u4e4b\u539f\u578b\u6a21\u5f0f<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Java \u4e2d\u521b\u5efa\u5bf9\u8c61\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u6bd4\u5982\uff1a\u901a\u8fc7 new\u3001\u53cd\u5c04\u3001Object.clone\u3001\u53cd\u5e8f\u5217\u5316\u3001Unsafe.allocateInstance \u7b49\u3002\u4ed6\u4eec\u7684\u7528\u5904\u5404\u4e0d\u76f8\u540c\uff0c\u4eca\u5929\u6211\u501f\u52a9 Object.clone \u6765\u8bb2\u4e00\u4e2a\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u578b\u6a21\u5f0f\uff08Prototype Pattern\uff09\u662f\u7528\u4e8e\u521b\u5efa\u91cd\u590d\u7684\u5bf9\u8c61\uff0c\u540c\u65f6\u53c8\u80fd\u4fdd\u8bc1\u6027\u80fd\u3002\u8fd9\u79cd\u7c7b\u578b\u7684\u8bbe\u8ba1\u6a21\u5f0f\u5c5e\u4e8e\u521b\u5efa\u578b\u6a21\u5f0f\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u521b\u5efa\u5bf9\u8c61\u7684\u6700\u4f73\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u76f4\u63a5\u521b\u5efa\u5bf9\u8c61\u7684\u4ee3\u4ef7\u6bd4\u8f83\u5927\u65f6\uff0c\u5219\u91c7\u7528\u8fd9\u79cd\u6a21\u5f0f\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a\u5bf9\u8c61\u9700\u8981\u5728\u4e00\u4e2a\u9ad8\u4ee3\u4ef7\u7684\u6570\u636e\u5e93\u64cd\u4f5c\u4e4b\u540e\u88ab\u521b\u5efa\u3002\u6211\u4eec\u53ef\u4ee5\u7f13\u5b58\u8be5\u5bf9\u8c61\uff0c\u5728\u4e0b\u4e00\u4e2a\u8bf7\u6c42\u65f6\u8fd4\u56de\u5b83\u7684\u514b\u9686\uff0c\u5728\u9700\u8981\u7684\u65f6\u5019\u66f4\u65b0\u6570\u636e\u5e93\uff0c\u4ee5\u6b64\u6765\u51cf\u5c11\u6570\u636e\u5e93\u8c03\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u73b0\u5b9e\u751f\u6d3b\u4e2d\u4e5f\u5904\u5904\u79bb\u4e0d\u5f00\u539f\u578b\u6a21\u5f0f\u3002\u6bd4\u5982\uff0c\u7ec6\u80de\u7684\u5206\u88c2\u7b49\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u578b\u6a21\u5f0f\u975e\u5e38\u7684\u7b80\u5355\u3002\u7b80\u5355\u5230\u53ef\u4ee5\u7528\u4e0b\u9762\u7684 3 \u4e2a\u7c7b\u641e\u5b9a\u5b83\u7684\u7c7b\u56fe\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcly1g5j0wgl4zoj20oe0cogmj.jpg\" alt=\"\" \/><figcaption>\u539f\u578b\u6a21\u5f0f\u7c7b\u56fe<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u5e38\u89c1\u7684\u6e38\u620f\u6253\u98de\u673a\uff0c\u6216\u8005\u690d\u7269\u5927\u6218\u50f5\u5c38\u3002\u90fd\u53ef\u4ee5\u5229\u7528\u5230\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcly1g5j0xzhhbtj20rs0mfaby.jpg\" alt=\"\" \/><figcaption>\u539f\u578b\u6a21\u5f0f\u5728\u6253\u98de\u673a\u6e38\u620f\u4e2d\u7684\u4f7f\u7528<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u4e2a\u98de\u673a\uff0c\u6216\u8005\u70ae\u5f39\u7684\u5750\u6807\u53ef\u80fd\u4e0d\u4e00\u6837\uff0c\u4f46\u662f\u8981\u4ea7\u751f\u975e\u5e38\u591a\u7684\u98de\u673a\uff0c\u5982\u679c\u4e00\u4e2a\u4e00\u4e2a\u7684\u6765\u521b\u5efa\uff0c\u4ee3\u4ef7\u592a\u9ad8\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u539f\u578b\u6a21\u5f0f\u6765\u89e3\u51b3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class AirPlane implements Cloneable{\n    private int x;\/\/\u6a2a\u5750\u6807\n    private int y = 0;\/\/\u7eb5\u5750\u6807\n    public AirPlane(int x) {\/\/\u6784\u9020\u5668\n        this.x = x;\n    }\n    public int getX() {\n        return x;\n    }\n    public int getY() {\n        return y;\n    }\n    public void setX(int x) {\n        this.x = x;\n    }\n    public void fly(){\n        y += 5;\n    }\n    \/\/\u91cd\u5199\u514b\u9686\u65b9\u6cd5\n    @Override\n    public AirPlane clone() throws CloneNotSupportedException {\n        return (AirPlane)super.clone();\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u578b\u6a21\u5f0f\u975e\u5e38\u7684\u7b80\u5355\uff0c\u6709\u4e9b\u7f51\u53cb\u53ef\u80fd\u4f1a\u89c9\u5f97\u96be\uff0c\u90a3\u662f\u56e0\u4e3a\u5b83\u7684\u4f7f\u7528\u573a\u666f\u4f60\u6ca1\u6709\u641e\u6e05\u695a\u3002\u4e0b\u9762\u6211\u603b\u7ed3\u4e86\u4e00\u4e0b\u539f\u578b\u6a21\u5f0f\u7684\u5e38\u7528\u573a\u666f\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8d44\u6e90\u4f18\u5316\u573a\u666f\u3002<\/li><li>\u7c7b\u521d\u59cb\u5316\u9700\u8981\u6d88\u5316\u975e\u5e38\u591a\u7684\u8d44\u6e90\uff0c\u8fd9\u4e2a\u8d44\u6e90\u5305\u62ec\u6570\u636e\u3001\u786c\u4ef6\u8d44\u6e90\u7b49\u3002<\/li><li>\u6027\u80fd\u548c\u5b89\u5168\u8981\u6c42\u7684\u573a\u666f\u3002<\/li><li>\u901a\u8fc7 new \u4ea7\u751f\u4e00\u4e2a\u5bf9\u8c61\u9700\u8981\u975e\u5e38\u7e41\u7410\u7684\u6570\u636e\u51c6\u5907\u6216\u8bbf\u95ee\u6743\u9650\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u539f\u578b\u6a21\u5f0f\u3002<\/li><li>\u4e00\u4e2a\u5bf9\u8c61\u591a\u4e2a\u4fee\u6539\u8005\u7684\u573a\u666f\u3002<\/li><li>\u4e00\u4e2a\u5bf9\u8c61\u9700\u8981\u63d0\u4f9b\u7ed9\u5176\u4ed6\u5bf9\u8c61\u8bbf\u95ee\uff0c\u800c\u4e14\u5404\u4e2a\u8c03\u7528\u8005\u53ef\u80fd\u90fd\u9700\u8981\u4fee\u6539\u5176\u503c\u65f6\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u539f\u578b\u6a21\u5f0f\u62f7\u8d1d\u591a\u4e2a\u5bf9\u8c61\u4f9b\u8c03\u7528\u8005\u4f7f\u7528\u3002 <\/li><li>\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u539f\u578b\u6a21\u5f0f\u5f88\u5c11\u5355\u72ec\u51fa\u73b0\uff0c\u4e00\u822c\u662f\u548c\u5de5\u5382\u65b9\u6cd5\u6a21\u5f0f\u4e00\u8d77\u51fa\u73b0\uff0c\u901a\u8fc7 clone \u7684\u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\uff0c\u7136\u540e\u7531\u5de5\u5382\u65b9\u6cd5\u63d0\u4f9b\u7ed9\u8c03\u7528\u8005\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u8fd9\u51e0\u4e2a\u573a\u666f\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u770b\u51fa\u6765\uff0c\u539f\u578b\u6a21\u5f0f\uff1a\u80fd\u591f\u63d0\u9ad8\u6027\u80fd\uff1b\u540c\u65f6\u8fd8\u80fd\u591f\u9003\u907f\u6784\u9020\u51fd\u6570\u7684\u7ea6\u675f\u3002\u4f46\u662f\u9664\u4e86\u8fd9\u4e24\u4e2a\u4f18\u70b9\u5916\uff0c\u7f3a\u70b9\u4e5f\u5f88\u660e\u663e\u3002\u5fc5\u987b\u5b9e\u73b0 Cloneable \u63a5\u53e3\uff1b\u5e76\u4e14\u7279\u522b\u5f53\u4e00\u4e2a\u7c7b\u5f15\u7528\u4e0d\u652f\u6301\u4e32\u884c\u5316\u7684\u95f4\u63a5\u5bf9\u8c61\uff0c\u6216\u8005\u5f15\u7528\u542b\u6709\u5faa\u73af\u7ed3\u6784\u7684\u65f6\u5019\uff0c\u514b\u9686\u7684\u6df1\u5ea6\u4f60\u5c31\u5f97\u901a\u76d8\u8003\u8651\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bbe\u8ba1\u6a21\u5f0f\u5f88\u591a\u4eba\u90fd\u770b\u8fc7\u5f88\u591a\u904d\u4e86\uff0c\u4f46\u662f\u4e00\u5230\u9762\u8bd5\u8fd8\u662f\u4e0d\u4f1a\u3002\u539f\u56e0\u5c31\u662f\u4f7f\u7528\u7684\u573a\u666f\u4e0d\u719f\u6089\uff0c\u5e76\u4e14\u6ca1\u6709\u5728\u6b63\u5f0f\u7684\u4ee3\u7801\u4e2d\u4f7f\u7528\u8fc7\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4442\">\u8bbe\u8ba1\u6a21\u5f0f\u7cfb\u5217\uff0c\u539f\u578b\u6a21\u5f0f<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5728\u9762\u8bd5\u4e2d\uff0c\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u6e90\u7801\u3001\u6570\u636e\u7ed3\u6784\u3001\u6846\u67b6\u539f\u7406\u3001JVM\u3001GC\u3001\u4e2d\u95f4\u4ef6\u7b49\u4e00\u4e2a\u4e5f\u5c11\u4e0d\u4e86\uff0c\u6240\u6709\u7684\u8fd9\u4e9b\u4e1c\u897f\u90fd\u9700\u8981\u5e73\u65f6\u8fdb\u884c [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[391,79,76,104,1143],"class_list":["post-4442","post","type-post","status-publish","format-standard","hentry","category-java","tag-mysql","tag-79","tag-76","tag-104","tag-1143"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4442"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4442\/revisions"}],"predecessor-version":[{"id":4443,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4442\/revisions\/4443"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}