{"id":844,"date":"2022-10-11T22:24:19","date_gmt":"2022-10-11T14:24:19","guid":{"rendered":"https:\/\/qaqaq.top\/?p=844"},"modified":"2022-11-27T12:39:54","modified_gmt":"2022-11-27T04:39:54","slug":"%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%8b-%e5%8d%95%e4%be%8b%e7%9a%84%e9%a5%bf%e6%b1%89%e5%bc%8f%e5%ae%9e%e7%8e%b0%e3%80%81%e9%a5%bf%e6%b1%89%e5%bc%8f%e5%92%8c%e6%87%92%e6%b1%89%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=844","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e0b)-\u5355\u4f8b\u7684\u997f\u6c49\u5f0f\u5b9e\u73b0\u3001\u997f\u6c49\u5f0f\u548c\u61d2\u6c49\u5f0f\u7684\u5bf9\u6bd4"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P325;\r\n\/*\r\n * \u5355\u4f8b\u8bbe\u8ba1\u6a21\u5f0f\uff1a\r\n * 1. \u6240\u8c13\u7c7b\u7684\u5355\u4f8b\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u5c31\u662f\u91c7\u53d6\u4e00\u5b9a\u7684\u65b9\u6cd5\u4fdd\u8bc1\u5728\u6574\u4e2a\u7684\u8f6f\u4ef6\u7cfb\u7edf\u4e2d\uff0c\u5bf9\u67d0\u4e2a\u7c7b\u53ea\u80fd\u5b58\u5728\u4e00\u4e2a\u5bf9\u8c61\u5b9e\u4f8b\u3002\r\n * \r\n * 2. \u5982\u4f55\u5b9e\u73b0\uff1f\r\n * \t\t\u997f\u6c49\u5f0f vs \u61d2\u6c49\u5f0f\r\n * \r\n * 3. \u533a\u5206\u997f\u6c49\u5f0f \u548c \u61d2\u6c49\u5f0f\r\n * \t\t\u997f\u6c49\u5f0f\uff1a\r\n * \t\t\t\u574f\u5904\uff1a\u5bf9\u8c61\u52a0\u8f7d\u65f6\u95f4\u8fc7\u957f\u3002\r\n * \t\t\t\u597d\u5904\uff1a\u997f\u6c49\u5f0f\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\r\n * \t\t\u61d2\u6c49\u5f0f\uff1a\u597d\u5904\uff1a\u5ef6\u8fdf\u5bf9\u8c61\u7684\u521b\u5efa\u3002\r\n * \t\t\t\u76ee\u524d\u7684\u5199\u6cd5\u574f\u5904\uff1a\u7ebf\u7a0b\u4e0d\u5b89\u5168\u3002--->\u5230\u591a\u7ebf\u7a0b\u5185\u5bb9\u65f6\uff0c\u518d\u4fee\u6539\r\n * \r\n *\/\r\npublic class SingletonTest1 {\r\n\r\n\tpublic static void main(String&#91;] args) {\r\n\t\t\r\n\/\/\t\tBank bank1 = new Bank();\r\n\/\/\t\tBank bank2 = new Bank();\r\n\t\tBank bank1 = Bank.getInstance();\r\n\t\tBank bank2 = Bank.getInstance();\r\n\t\t\r\n\t\tSystem.out.println(bank1 == bank2);\r\n\t}\r\n}\r\n\r\n\/\/\u997f\u6c49\u5f0f\r\nclass Bank{\r\n\t\r\n\t\/\/1. \u79c1\u6709\u5316\u7c7b\u7684\u6784\u9020\u5668\r\n\tprivate Bank() {\r\n\t\t\r\n\t}\r\n\t\r\n\t\/\/2. \u5185\u90e8\u521b\u5efa\u7c7b\u7684\u5bf9\u8c61\r\n\t\/\/4. \u8981\u6c42\u6b64\u5bf9\u8c61\u4e5f\u5fc5\u987b\u58f0\u660e\u4e3a\u9759\u6001\u7684\r\n\tprivate static Bank instance = new Bank();\r\n\t\r\n\t\/\/3. \u63d0\u4f9b\u516c\u5171\u7684\u9759\u6001\u7684\u65b9\u6cd5\uff0c\u8fd4\u56de\u7c7b\u7684\u5bf9\u8c61\r\n\tpublic static Bank getInstance() {\r\n\t\treturn instance;\r\n\t}\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-844","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/844"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=844"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/844\/revisions"}],"predecessor-version":[{"id":845,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/844\/revisions\/845"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}