{"id":40184,"date":"2024-11-26T12:43:47","date_gmt":"2024-11-26T04:43:47","guid":{"rendered":"https:\/\/fwq.ai\/blog\/40184\/"},"modified":"2024-11-26T12:43:47","modified_gmt":"2024-11-26T04:43:47","slug":"java%e6%80%8e%e4%b9%88%e5%ae%9a%e4%b9%89%e4%b8%80%e4%b8%aa%e6%95%b0%e7%bb%84%e7%9a%84%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/40184\/","title":{"rendered":"java\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\u7684\u7c7b"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\u5b9a\u4e49\u6570\u7ec4\u7c7b\u5206\u4e3a\u5177\u4f53\u7c7b\u578b\u6570\u7ec4\u7c7b\u548c\u6cdb\u578b\u6570\u7ec4\u7c7b\u4e24\u79cd\u65b9\u5f0f\uff1a\u5b9a\u4e49\u5177\u4f53\u7c7b\u578b\u6570\u7ec4\u7c7b\uff1a\u4f7f\u7528 int[]\u3001string[] \u7b49\u8bed\u6cd5\u5b9a\u4e49\u4e00\u4e2a\u53ea\u80fd\u5bb9\u7eb3\u7279\u5b9a\u7c7b\u578b\u6570\u636e\u7684\u6570\u7ec4\u7c7b\u3002\u5b9a\u4e49\u6cdb\u578b\u6570\u7ec4\u7c7b\uff1a\u4f7f\u7528\u6cdb\u578b\u8bed\u6cd5\u5b9a\u4e49\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u4f55\u7c7b\u578b\u6570\u636e\u7684\u6570\u7ec4\u7c7b\uff0c\u5982 genericarray\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111722242698152.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\u7684\u7c7b\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\u7684\u7c7b\u63d2\u56fe\" \/><\/p>\n<h2>\u5982\u4f55\u5728 Java \u4e2d\u5b9a\u4e49\u6570\u7ec4\u7c7b<\/h2>\n<p>\u5728 Java \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 int[]\u3001String[] \u7b49\u8bed\u6cd5\u5b9a\u4e49\u6570\u7ec4\u7c7b\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6cdb\u578b\u6570\u7ec4\u7c7b\u8bed\u6cd5\u6765\u5b9a\u4e49\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u4f55\u7c7b\u578b\u6570\u636e\u7684\u6570\u7ec4\u7c7b\u3002<\/p>\n<p><strong>1. \u5b9a\u4e49\u4e00\u4e2a\u5177\u4f53\u7c7b\u578b\u6570\u7ec4\u7c7b<\/strong><\/p>\n<pre>public class IntegerArray {\n\n    private int[] array;\n\n    public IntegerArray(int size) {\n        this.array = new int[size];\n    }\n\n    \/\/ \u6dfb\u52a0getter\u548csetter\u65b9\u6cd5\n    \/\/ ...\n\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5b9a\u4e49\u4e00\u4e2a\u6cdb\u578b\u6570\u7ec4\u7c7b<\/strong><\/p>\n<pre>public class GenericArray&lt;T&gt; {\n\n    private T[] array;\n\n    public GenericArray(int size) {\n        this.array = (T[]) new Object[size];\n    }\n\n    \/\/ \u6dfb\u52a0getter\u548csetter\u65b9\u6cd5\n    \/\/ ...\n\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6570\u7ec4\u7c7b\u7684\u7279\u70b9\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li> <strong>\u6570\u7ec4\u957f\u5ea6\u56fa\u5b9a\uff1a<\/strong>\u4e00\u65e6\u521b\u5efa\uff0c\u6570\u7ec4\u7684\u5927\u5c0f\u5c31\u4e0d\u80fd\u6539\u53d8\u3002<\/li>\n<li> <strong>\u5143\u7d20\u7c7b\u578b\u56fa\u5b9a\uff1a<\/strong>\u5177\u4f53\u7c7b\u578b\u6570\u7ec4\u7c7b\u53ea\u80fd\u5bb9\u7eb3\u7279\u5b9a\u7c7b\u578b\u7684\u6570\u636e\uff0c\u800c\u6cdb\u578b\u6570\u7ec4\u7c7b\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u4f55\u7c7b\u578b\u7684\u6570\u636e\u3002<\/li>\n<li> <strong>\u4f7f\u7528getter\u548csetter\u65b9\u6cd5\uff1a<\/strong>\u4e3a\u4e86\u5b89\u5168\u5730\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u7ec4\u5143\u7d20\uff0c\u4f7f\u7528getter\u548csetter\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\u7684\u7c7b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 java \u4e2d\u5b9a\u4e49\u6570\u7ec4\u7c7b\u5206\u4e3a\u5177\u4f53\u7c7b\u578b\u6570\u7ec4\u7c7b\u548c\u6cdb\u578b\u6570\u7ec4\u7c7b\u4e24\u79cd\u65b9\u5f0f\uff1a\u5b9a\u4e49\u5177\u4f53\u7c7b\u578b\u6570\u7ec4\u7c7b\uff1a\u4f7f\u7528 int[]\u3001string[] \u7b49\u8bed\u6cd5\u5b9a\u4e49\u4e00\u4e2a\u53ea\u80fd\u5bb9\u7eb3\u7279\u5b9a\u7c7b\u578b\u6570\u636e\u7684\u6570\u7ec4\u7c7b\u3002\u5b9a\u4e49\u6cdb\u578b\u6570\u7ec4\u7c7b\uff1a\u4f7f\u7528\u6cdb\u578b\u8bed\u6cd5\u5b9a\u4e49\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u4f55\u7c7b\u578b\u6570\u636e\u7684\u6570\u7ec4\u7c7b\uff0c\u5982 genericarray\u3002 \u5982\u4f55\u5728 Java \u4e2d\u5b9a\u4e49\u6570\u7ec4\u7c7b \u5728 Java \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 int[]\u3001String[] \u7b49\u8bed\u6cd5\u5b9a\u4e49\u6570\u7ec4\u7c7b\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6cdb\u578b\u6570\u7ec4\u7c7b\u8bed\u6cd5\u6765\u5b9a\u4e49\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u4f55\u7c7b\u578b\u6570\u636e\u7684\u6570\u7ec4\u7c7b\u3002 1. \u5b9a\u4e49\u4e00\u4e2a\u5177\u4f53\u7c7b\u578b\u6570\u7ec4\u7c7b public class IntegerArray { private int[] array; public IntegerArray(int size) { this.array = new int[size]; } \/\/ \u6dfb\u52a0getter\u548csetter\u65b9\u6cd5 \/\/ &#8230; } \u767b\u5f55\u540e\u590d\u5236 2. \u5b9a\u4e49\u4e00\u4e2a\u6cdb\u578b\u6570\u7ec4\u7c7b public class GenericArray&lt;T&gt; { private T[] array; public GenericArray(int size) { this.array = (T[]) new [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-40184","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=40184"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40184\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=40184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=40184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=40184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}