{"id":283,"date":"2026-07-19T14:43:03","date_gmt":"2026-07-19T06:43:03","guid":{"rendered":"http:\/\/ssjava.xyz\/index.php\/2026\/07\/19\/javase-03-%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1-%e2%86%92-%e2%91%a5%e5%86%85%e9%83%a8%e7%b1%bb%c2%b7%e4%b8%8a%ef%bc%88%e6%88%90%e5%91%98%e5%86%85%e9%83%a8%e7%b1%bb%e9%9d%99%e6%80%81%e5%86%85\/"},"modified":"2026-07-19T14:55:41","modified_gmt":"2026-07-19T06:55:41","slug":"22-%e5%86%85%e9%83%a8%e7%b1%bb%c2%b7%e4%b8%8a%ef%bc%88%e6%88%90%e5%91%98%e5%86%85%e9%83%a8%e7%b1%bb%e9%9d%99%e6%80%81%e5%86%85%e9%83%a8%e7%b1%bb%ef%bc%89","status":"publish","type":"post","link":"https:\/\/ssjava.xyz\/index.php\/2026\/07\/19\/22-%e5%86%85%e9%83%a8%e7%b1%bb%c2%b7%e4%b8%8a%ef%bc%88%e6%88%90%e5%91%98%e5%86%85%e9%83%a8%e7%b1%bb%e9%9d%99%e6%80%81%e5%86%85%e9%83%a8%e7%b1%bb%ef%bc%89\/","title":{"rendered":"22. \u5185\u90e8\u7c7b\u00b7\u4e0a\uff08\u6210\u5458\u5185\u90e8\u7c7b&amp;\u9759\u6001\u5185\u90e8\u7c7b\uff09"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u9762\u5411\u5bf9\u8c61\u5b66\u4e86\u8fd9\u4e48\u591a\uff0c\u4f60\u6709\u6ca1\u6709\u60f3\u8fc7\u4e00\u4e2a\u95ee\u9898\uff1a\u4e00\u4e2a\u7c7b\uff0c\u80fd\u4e0d\u80fd\u5199\u5728\u53e6\u4e00\u4e2a\u7c7b\u7684<strong>\u91cc\u9762<\/strong>\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u7b2c\u4e00\u6b21\u542c\u5230\u8fd9\u4e2a\u8bf4\u6cd5\u7684\u65f6\u5019\uff0c\u7b2c\u4e00\u53cd\u5e94\u5c31\u662f\u2014\u2014\u554a\uff1f\u7c7b\u5957\u7c7b\uff1f\u8fd9\u4e0d\u662f\u5957\u5a03\u5417\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u7b49\u4f60\u771f\u641e\u61c2\u4e86\uff0c\u4f1a\u53d1\u73b0\u5185\u90e8\u7c7b\uff08Inner Class\uff09\u662f Java \u91cc\u8bbe\u8ba1\u5f97\u975e\u5e38\u7cbe\u5de7\u7684\u4e00\u4e2a\u8bed\u6cd5\u3002\u5b83\u4e0d\u662f\u70ab\u6280\uff0c\u800c\u662f\u89e3\u51b3\u4e86\u4e00\u4e9b<strong>\u5916\u90e8\u7c7b\u5185\u90e8\u903b\u8f91\u9ad8\u5185\u805a<\/strong>\u7684\u95ee\u9898\u2014\u2014\u8bf4\u5230\u5e95\u5c31\u662f\uff1a\u6709\u4e9b\u7c7b\u53ea\u670d\u52a1\u4e8e\u53e6\u4e00\u4e2a\u7c7b\uff0c\u6ca1\u5fc5\u8981\u6254\u5230\u5916\u9762\u8ddf\u4eba\u5bb6\u5e73\u8d77\u5e73\u5750\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4ec0\u4e48\u662f\u5185\u90e8\u7c7b\uff1f\u4e3a\u4ec0\u4e48\u8981\u7528\uff1f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9a\u4e49\u5f88\u7b80\u5355\uff1a<strong>\u5728\u67d0\u4e2a\u7c7b\u7684\u5185\u90e8\u518d\u5b9a\u4e49\u4e00\u4e2a\u7c7b\uff0c\u5c31\u53eb\u5185\u90e8\u7c7b<\/strong>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Outer {\n    class Inner {\n        \/\/ \u5185\u90e8\u7c7b\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u80fd\u4f1a\u8bf4\uff0c\u5206\u5f00\u5b9a\u4e49\u4e0d\u5c31\u884c\u4e86\uff0c\u4f55\u5fc5\u5d4c\u5957\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u573a\u666f\u6765\u4e86\uff1a\u4f60\u5199\u4e00\u4e2a <code>LinkedList<\/code>\uff08\u53cc\u5411\u94fe\u8868\uff09\u3002\u94fe\u8868\u7531\u4e00\u4e2a\u4e2a\u8282\u70b9\u7ec4\u6210\uff0c\u8fd9\u4e2a <code>Node<\/code> \u7c7b\u53ea\u670d\u52a1\u4e8e <code>LinkedList<\/code>\uff0c\u5bf9\u5916\u754c\u6765\u8bf4 <code>Node<\/code> \u5c31\u662f\u4e00\u4e2a\u5b9e\u73b0\u7ec6\u8282\uff0c\u4f60\u5b8c\u5168\u6ca1\u5fc5\u8981\u628a\u5b83\u5b9a\u4e49\u6210\u4e00\u4e2a\u516c\u5f00\u7684\u9876\u5c42\u7c7b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5185\u90e8\u7c7b\u7684\u6838\u5fc3\u4f18\u52bf\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5c01\u88c5\u6027<\/strong>\uff1a\u5916\u90e8\u4e0d\u9700\u8981\u77e5\u9053\u5185\u90e8\u7c7b\u7684\u5b58\u5728\uff0c\u5b9e\u73b0\u7ec6\u8282\u85cf\u5f97\u4e25\u4e25\u5b9e\u5b9e<\/li>\n\n\n\n<li><strong>\u76f4\u63a5\u8bbf\u95ee\u5916\u90e8\u7c7b\u6210\u5458<\/strong>\uff1a\u5185\u90e8\u7c7b\u5929\u7136\u6301\u6709\u5916\u90e8\u7c7b\u5bf9\u8c61\u7684\u5f15\u7528\uff08\u9690\u5f0f\u7684\uff09\uff0c\u53ef\u4ee5\u81ea\u7531\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684 <strong>\u6240\u6709<\/strong> \u6210\u5458\uff0c\u5305\u62ec <code>private<\/code> \u7684<\/li>\n\n\n\n<li><strong>\u4ee3\u7801\u7ec4\u7ec7\u6027<\/strong>\uff1a\u903b\u8f91\u4e0a\u5c5e\u4e8e\u4e00\u8d77\u7684\u4ee3\u7801\uff0c\u7269\u7406\u4e0a\u4e5f\u653e\u5728\u4e00\u8d77<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u5185\u90e8\u7c7b\u7684\u56db\u79cd\u7c7b\u578b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Java \u7684\u5185\u90e8\u7c7b\u5206\u56db\u79cd\uff0c\u4e00\u4e2a\u4e00\u4e2a\u6765\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6210\u5458\u5185\u90e8\u7c7b<\/strong>\uff08Member Inner Class\uff09\u2014\u2014 \u6700\u57fa\u7840\u7684\u90a3\u79cd<\/li>\n\n\n\n<li><strong>\u9759\u6001\u5185\u90e8\u7c7b<\/strong>\uff08Static Nested Class\uff09\u2014\u2014 \u52a0\u4e86 <code>static<\/code> \u7684<\/li>\n\n\n\n<li><strong>\u5c40\u90e8\u5185\u90e8\u7c7b<\/strong>\uff08Local Inner Class\uff09\u2014\u2014 \u5199\u5728\u65b9\u6cd5\u91cc\u7684<\/li>\n\n\n\n<li><strong>\u533f\u540d\u5185\u90e8\u7c7b<\/strong>\uff08Anonymous Inner Class\uff09\u2014\u2014 \u8fde\u540d\u5b57\u90fd\u6ca1\u6709\u7684<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u7bc7\u6211\u4eec\u5148\u8bb2\u524d\u4e24\u79cd\u2014\u2014\u6210\u5458\u5185\u90e8\u7c7b\u548c\u9759\u6001\u5185\u90e8\u7c7b\u3002\u5c40\u90e8\u5185\u90e8\u7c7b\u548c\u533f\u540d\u5185\u90e8\u7c7b\u4e0b\u7bc7\u518d\u8bf4\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u6210\u5458\u5185\u90e8\u7c7b\uff08Member Inner Class\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6210\u5458\u5185\u90e8\u7c7b\u5c31\u662f\u6700\u7b80\u5355\u7c97\u66b4\u7684\uff1a\u628a\u4e00\u4e2a\u7c7b\u4e0d\u52a0 <code>static<\/code>\u3001\u4e0d\u5199\u65b9\u6cd5\u91cc\uff0c\u5c31\u653e\u5728\u5916\u90e8\u7c7b\u7684\u6210\u5458\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 \u57fa\u672c\u5199\u6cd5<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Outer {\n\n    private String name = \"\u6211\u662f\u5916\u90e8\u7c7b\";\n\n    \/\/ \u6210\u5458\u5185\u90e8\u7c7b\n    public class Inner {\n        public void show() {\n            \/\/ \u5185\u90e8\u7c7b\u76f4\u63a5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684 private \u6210\u5458\n            System.out.println(name);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8c03\u7528\u7684\u65f6\u5019\u8981\u6ce8\u610f\uff0c\u6210\u5458\u5185\u90e8\u7c7b<strong>\u4f9d\u8d56\u5916\u90e8\u7c7b\u5bf9\u8c61\u800c\u5b58\u5728<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Test {\n    public static void main(String&#91;] args) {\n        Outer outer = new Outer();\n        Outer.Inner inner = outer.new Inner();  \/\/ \u6ce8\u610f\u8fd9\u4e2a\u8bed\u6cd5\n        inner.show();  \/\/ \u8f93\u51fa\uff1a\u6211\u662f\u5916\u90e8\u7c7b\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>outer.new Inner()<\/code> \u8fd9\u4e2a\u5199\u6cd5\u7b2c\u4e00\u6b21\u89c1\u80af\u5b9a\u89c9\u5f97\u5947\u602a\u2014\u2014\u8bb0\u4f4f\u5c31\u884c\uff0c\u5b83\u7684\u610f\u601d\u662f\u300c\u901a\u8fc7\u4e00\u4e2a\u5916\u90e8\u7c7b\u5bf9\u8c61\u6765\u521b\u5efa\u5185\u90e8\u7c7b\u5bf9\u8c61\u300d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 \u5185\u90e8\u7c7b\u6301\u6709\u5916\u90e8\u7c7b\u5f15\u7528 \u2014\u2014 Outer.this<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6210\u5458\u5185\u90e8\u7c7b\u80cc\u540e\u6709\u4e2a\u91cd\u8981\u673a\u5236\uff1a\u6bcf\u4e2a\u6210\u5458\u5185\u90e8\u7c7b\u5bf9\u8c61\u5185\u90e8\uff0c\u90fd\u9690\u5f0f\u6301\u6709\u4e00\u4e2a<strong>\u5916\u90e8\u7c7b\u5bf9\u8c61\u5f15\u7528<\/strong>\uff0c\u901a\u8fc7 <code>Outer.this<\/code> \u8bbf\u95ee\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bd4\u5982\u5916\u90e8\u7c7b\u548c\u5185\u90e8\u7c7b\u6709\u540c\u540d\u6210\u5458\u53d8\u91cf\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Outer {\n    private String msg = \"\u5916\u90e8\u6d88\u606f\";\n\n    public class Inner {\n        private String msg = \"\u5185\u90e8\u6d88\u606f\";\n\n        public void show() {\n            String msg = \"\u5c40\u90e8\u6d88\u606f\";\n            System.out.println(msg);          \/\/ \u5c40\u90e8\u6d88\u606f\n            System.out.println(this.msg);     \/\/ \u5185\u90e8\u6d88\u606f\n            System.out.println(Outer.this.msg); \/\/ \u5916\u90e8\u6d88\u606f\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Outer.this<\/code> \u5c31\u662f\u90a3\u4e2a\u9690\u5f0f\u7684\u5916\u90e8\u7c7b\u5f15\u7528\u3002\u4e09\u5c42\u540c\u540d\u53d8\u91cf\uff0c\u5c42\u5c42\u90fd\u80fd\u533a\u5206\uff0cJava \u7684\u547d\u540d\u7a7a\u95f4\u62c6\u5f97\u5f88\u7ec6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.3 \u6743\u9650\u4fee\u9970\u7b26<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6210\u5458\u5185\u90e8\u7c7b\u53ef\u4ee5\u52a0 <code>private<\/code>\u3001<code>protected<\/code>\u3001<code>\u9ed8\u8ba4<\/code>\u3001<code>public<\/code>\u2014\u2014\u5b83\u8ddf\u6210\u5458\u53d8\u91cf\u4e00\u6837\uff0c<strong>\u8bbf\u95ee\u63a7\u5236\u5168\u770b\u4f60\u9700\u8981<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u5e38\u89c1\u7684\u7528\u6cd5\u5c31\u662f <code>private<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class LinkedList {\n\n    \/\/ \u5185\u90e8\u7c7b\u79c1\u6709\u5316\uff0c\u5916\u90e8\u5b8c\u5168\u4e0d\u77e5\u9053 Node \u7684\u5b58\u5728\n    private class Node {\n        int data;\n        Node prev;\n        Node next;\n\n        Node(int data) {\n            this.data = data;\n        }\n    }\n\n    private Node head;\n\n    public void addFirst(int data) {\n        Node newNode = new Node(data);\n        newNode.next = head;\n        if (head != null) {\n            head.prev = newNode;\n        }\n        head = newNode;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u5c31\u662f\u5185\u90e8\u7c7b\u6700\u7ecf\u5178\u7684\u5e94\u7528\u573a\u666f\uff1a<strong>\u5b9e\u73b0\u7ec6\u8282\u5bf9\u5916\u754c\u5b8c\u5168\u9690\u85cf<\/strong>\u3002\u8c03\u7528\u8005\u53ea\u9700\u8981 <code>list.addFirst(10)<\/code>\uff0c\u6839\u672c\u4e0d\u77e5\u9053\u91cc\u9762\u8fd8\u6709\u4e2a <code>Node<\/code>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u9759\u6001\u5185\u90e8\u7c7b\uff08Static Nested Class\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6210\u5458\u5185\u90e8\u7c7b\u52a0\u4e2a <code>static<\/code> \u5c31\u6210\u4e86\u9759\u6001\u5185\u90e8\u7c7b\u2014\u2014\u4f46\u5b83\u4fe9\u7684\u5dee\u522b\u4e0d\u5c0f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.1 \u9759\u6001\u5185\u90e8\u7c7b\u7684\u7279\u70b9<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e0d\u6301\u6709\u5916\u90e8\u7c7b\u5f15\u7528<\/strong>\uff1a\u5b83\u4e0d\u4f9d\u8d56\u5916\u90e8\u7c7b\u5bf9\u8c61\uff0c\u8ddf <code>static<\/code> \u7684\u8bed\u4e49\u4e00\u81f4<\/li>\n\n\n\n<li><strong>\u53ea\u80fd\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u9759\u6001\u6210\u5458<\/strong>\uff1a\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u5b9e\u4f8b\u6210\u5458<\/li>\n\n\n\n<li><strong>\u521b\u5efa\u4e0d\u9700\u8981\u5916\u90e8\u7c7b\u5bf9\u8c61<\/strong>\uff1a<code>new Outer.StaticInner()<\/code> \u641e\u5b9a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Outer {\n    private static String staticMsg = \"\u9759\u6001\u6d88\u606f\";\n    private String instanceMsg = \"\u5b9e\u4f8b\u6d88\u606f\";\n\n    \/\/ \u9759\u6001\u5185\u90e8\u7c7b\n    public static class StaticInner {\n        public void print() {\n            System.out.println(staticMsg);      \/\/ \u2705 \u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u7c7b\u9759\u6001\u6210\u5458\n            \/\/ System.out.println(instanceMsg); \/\/ \u274c \u4e0d\u80fd\u8bbf\u95ee\u5b9e\u4f8b\u6210\u5458\n        }\n    }\n}\n\n\/\/ \u4f7f\u7528\u65b9\u5f0f\npublic class Test {\n    public static void main(String&#91;] args) {\n        Outer.StaticInner inner = new Outer.StaticInner();\n        inner.print();  \/\/ \u4e0d\u9700\u8981\u5916\u90e8\u7c7b\u5b9e\u4f8b\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4.2 \u7ecf\u5178\u7684\u5efa\u9020\u8005\u6a21\u5f0f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9759\u6001\u5185\u90e8\u7c7b\u6700\u51fa\u540d\u7684\u5e94\u7528\u5c31\u662f <strong>Builder \u6a21\u5f0f<\/strong>\u3002\u5f53\u4f60\u6709\u4e00\u4e2a\u7c7b\u9700\u8981\u5f88\u591a\u53ef\u9009\u53c2\u6570\u65f6\uff0c\u7528\u6784\u9020\u5668\u91cd\u8f7d\u80fd\u628a\u4f60\u641e\u75af\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u4f20\u7edf\u65b9\u5f0f\u2014\u2014\u53c2\u6570\u4e00\u591a\u6784\u9020\u5668\u5c31\u7206\u70b8\nUser user1 = new User(\"\u5f20\u4e09\", 20, \"\u5317\u4eac\", \"\u7537\", \"138xxxx\", \"zhangsan@qq.com\");\n\/\/ \u54ea\u4e2a\u53c2\u6570\u5bf9\u5e94\u54ea\u4e2a\uff1f\u6bcf\u6b21\u90fd\u5f97\u6570\u4f4d\u7f6e\uff0c\u70e6\u4e0d\u70e6<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528\u9759\u6001\u5185\u90e8\u7c7b + Builder \u6a21\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class User {\n    private final String name;      \/\/ \u5fc5\u586b\n    private final int age;          \/\/ \u5fc5\u586b\n    private final String city;      \/\/ \u53ef\u9009\n    private final String gender;    \/\/ \u53ef\u9009\n    private final String phone;     \/\/ \u53ef\u9009\n    private final String email;     \/\/ \u53ef\u9009\n\n    \/\/ \u79c1\u6709\u6784\u9020\u5668\u2014\u2014\u53ea\u80fd\u901a\u8fc7 Builder \u521b\u5efa\n    private User(Builder builder) {\n        this.name = builder.name;\n        this.age = builder.age;\n        this.city = builder.city;\n        this.gender = builder.gender;\n        this.phone = builder.phone;\n        this.email = builder.email;\n    }\n\n    \/\/ \u9759\u6001\u5185\u90e8\u7c7b\u4f5c\u4e3a Builder\n    public static class Builder {\n        private final String name;   \/\/ \u5fc5\u586b\uff0c\u8bbe\u4e3a final\n        private final int age;       \/\/ \u5fc5\u586b\n        private String city;\n        private String gender;\n        private String phone;\n        private String email;\n\n        public Builder(String name, int age) {\n            this.name = name;\n            this.age = age;\n        }\n\n        public Builder city(String city) { this.city = city; return this; }\n        public Builder gender(String gender) { this.gender = gender; return this; }\n        public Builder phone(String phone) { this.phone = phone; return this; }\n        public Builder email(String email) { this.email = email; return this; }\n\n        public User build() {\n            return new User(this);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8c03\u7528\u8d77\u6765\u5c31\u6e05\u723d\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>User user = new User.Builder(\"\u5f20\u4e09\", 20)\n        .city(\"\u5317\u4eac\")\n        .gender(\"\u7537\")\n        .email(\"zhangsan@qq.com\")\n        .build();\n\/\/ \u94fe\u5f0f\u8c03\u7528\uff0c\u6bcf\u4e00\u884c\u90fd\u770b\u5f97\u61c2\u53c2\u6570\u662f\u4ec0\u4e48\u610f\u601d<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f\u9759\u6001\u5185\u90e8\u7c7b\u6700\u4f18\u96c5\u7684\u7528\u6cd5\u3002\u6bcf\u5f53\u4f60\u5199\u4e00\u4e2a\u6784\u9020\u5668\u53c2\u6570\u8d85\u8fc7 3 \u4e2a\u7684\u7c7b\uff0c\u5c31\u8be5\u8003\u8651 Builder \u6a21\u5f0f\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u6210\u5458\u5185\u90e8\u7c7b vs \u9759\u6001\u5185\u90e8\u7c7b<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u5bf9\u6bd4\u7ef4\u5ea6<\/th><th>\u6210\u5458\u5185\u90e8\u7c7b<\/th><th>\u9759\u6001\u5185\u90e8\u7c7b<\/th><\/tr><\/thead><tbody><tr><td><strong>\u6301\u6709\u5916\u90e8\u7c7b\u5f15\u7528<\/strong><\/td><td>\u2705 \u6301\u6709\uff08\u9690\u5f0f <code>Outer.this<\/code>\uff09<\/td><td>\u274c \u4e0d\u6301\u6709<\/td><\/tr><tr><td><strong>\u8bbf\u95ee\u5916\u90e8\u5b9e\u4f8b\u6210\u5458<\/strong><\/td><td>\u2705 \u53ef\u4ee5<\/td><td>\u274c \u4e0d\u53ef\u4ee5<\/td><\/tr><tr><td><strong>\u8bbf\u95ee\u5916\u90e8\u9759\u6001\u6210\u5458<\/strong><\/td><td>\u2705 \u53ef\u4ee5<\/td><td>\u2705 \u53ef\u4ee5<\/td><\/tr><tr><td><strong>\u521b\u5efa\u65b9\u5f0f<\/strong><\/td><td><code>outer.new Inner()<\/code><\/td><td><code>new Outer.Inner()<\/code><\/td><\/tr><tr><td><strong>\u5185\u5b58\u5360\u7528<\/strong><\/td><td>\u989d\u5916\u6301\u6709\u5916\u90e8\u7c7b\u5f15\u7528\uff0c\u7a0d\u5927<\/td><td>\u6ca1\u6709\u989d\u5916\u5f15\u7528\uff0c\u66f4\u8f7b\u91cf<\/td><\/tr><tr><td><strong>\u5178\u578b\u573a\u666f<\/strong><\/td><td>\u9700\u8981\u53cc\u5411\u8bbf\u95ee\uff08\u5982\u94fe\u8868 Node\uff09<\/td><td>\u8f85\u52a9\u7c7b\uff08\u5982 Builder\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u7f16\u8bd1\u540e\u7684\u79d8\u5bc6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5185\u90e8\u7c7b\u7f16\u8bd1\u540e\u4f1a\u751f\u6210\u72ec\u7acb\u7684 <code>.class<\/code> \u6587\u4ef6\u3002\u4f60\u7f16\u8bd1 <code>Outer.java<\/code> \u4e4b\u540e\uff0c\u4f1a\u770b\u5230\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Outer.class\nOuter$Inner.class          \/\/ \u6210\u5458\u5185\u90e8\u7c7b\nOuter$StaticInner.class    \/\/ \u9759\u6001\u5185\u90e8\u7c7b<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u90a3\u4e2a <code>$<\/code> \u5c31\u662f Java \u533a\u5206\u5185\u90e8\u7c7b\u7684\u6807\u5fd7\u3002\u5982\u679c\u4f60\u5728\u547d\u4ee4\u884c\u91cc\u770b\u5230 <code>Outer$Inner.class<\/code> \u8fd9\u79cd\u6587\u4ef6\uff0c\u522b\u89c9\u5f97\u662f\u7cfb\u7edf\u62bd\u98ce\u2014\u2014\u90a3\u662f\u5185\u90e8\u7c7b\u7f16\u8bd1\u540e\u7684\u4ea7\u7269\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u89c4\u5219\u6211\u8bb0\u5f97\u6709\u4e00\u6b21\u5199\u4ee3\u7801\uff0c\u53cd\u7f16\u8bd1\u770b\u5b57\u8282\u7801\u7684\u65f6\u5019\u88ab\u8fd9\u4e2a <code>$<\/code> \u641e\u61f5\u8fc7\uff0c\u627e\u4e86\u534a\u5929\u624d\u53d1\u73b0\u662f\u5185\u90e8\u7c7b\u2026\u2026\u8bdd\u8bf4\u56de\u6765\uff0c\u641e\u61c2\u8fd9\u4e2a\u5bf9\u9762\u8bd5\u5f88\u6709\u7528\uff0c\u9762\u8bd5\u5b98\u7ecf\u5e38\u95ee\u300c\u5185\u90e8\u7c7b\u7f16\u8bd1\u540e\u751f\u6210\u51e0\u4e2a\u6587\u4ef6\u300d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001\u5c0f\u7ed3<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5185\u90e8\u7c7b\u5c31\u662f<strong>\u7c7b\u4e2d\u5b9a\u4e49\u7684\u7c7b<\/strong>\uff0c\u5b9e\u73b0\u4e86\u9ad8\u5185\u805a\u7684\u5c01\u88c5<\/li>\n\n\n\n<li><strong>\u6210\u5458\u5185\u90e8\u7c7b<\/strong>\u6301\u6709\u9690\u5f0f\u5916\u90e8\u7c7b\u5f15\u7528\uff0c\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u7c7b\u5168\u90e8\u6210\u5458<\/li>\n\n\n\n<li><strong>\u9759\u6001\u5185\u90e8\u7c7b<\/strong>\u4e0d\u6301\u6709\u5916\u90e8\u7c7b\u5f15\u7528\uff0c\u53ea\u80fd\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u9759\u6001\u6210\u5458<\/li>\n\n\n\n<li>\u5185\u90e8\u7c7b\u7f16\u8bd1\u540e\u751f\u6210 <code>\u5916\u90e8\u7c7b$\u5185\u90e8\u7c7b.class<\/code> \u6587\u4ef6<\/li>\n\n\n\n<li>Builder \u6a21\u5f0f\u662f\u9759\u6001\u5185\u90e8\u7c7b\u7684\u7ecf\u5178\u5e94\u7528\uff0c\u53c2\u6570\u591a\u7684\u7c7b\u7528\u5b83\u51c6\u6ca1\u9519<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u4e00\u7bc7\u6211\u4eec\u804a\u804a\u5c40\u90e8\u5185\u90e8\u7c7b\u548c\u533f\u540d\u5185\u90e8\u7c7b\u2014\u2014\u7279\u522b\u662f\u533f\u540d\u5185\u90e8\u7c7b\uff0c\u4f60\u5728\u5199 GUI \u4e8b\u4ef6\u3001Lambda \u8868\u8fbe\u5f0f\u8f6c\u8bd1\u3001\u7ebf\u7a0b\u521b\u5efa\u65f6\u5904\u5904\u90fd\u4f1a\u89c1\u5230\u5b83\uff0c\u975e\u5e38\u5b9e\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9762\u5411\u5bf9\u8c61\u5b66\u4e86\u8fd9\u4e48\u591a\uff0c\u4f60\u6709\u6ca1\u6709\u60f3\u8fc7\u4e00\u4e2a\u95ee\u9898\uff1a\u4e00\u4e2a\u7c7b\uff0c\u80fd\u4e0d\u80fd\u5199\u5728\u53e6\u4e00\u4e2a\u7c7b\u7684\u91cc\u9762\uff1f \u6211\u7b2c\u4e00\u6b21\u542c\u5230\u8fd9\u4e2a\u8bf4\u6cd5\u7684\u65f6\u5019\uff0c\u7b2c\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70,10],"tags":[96,95,92,93,94],"class_list":["post-283","post","type-post","status-publish","format-standard","hentry","category-06-inner-class","category-javase","tag-96","tag-builder","tag-92","tag-93","tag-94"],"_links":{"self":[{"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/posts\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=283"}],"version-history":[{"count":3,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":292,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/posts\/283\/revisions\/292"}],"wp:attachment":[{"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ssjava.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}