{"id":202641,"date":"2025-05-22T08:41:45","date_gmt":"2025-05-22T00:41:45","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202641\/"},"modified":"2025-05-22T08:41:45","modified_gmt":"2025-05-22T00:41:45","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87-javadoc-%e6%b3%a8%e9%87%8a%e6%9d%a5%e6%8f%8f%e8%bf%b0-varargs-%e5%8f%82%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202641\/","title":{"rendered":"\u5982\u4f55\u901a\u8fc7 javadoc \u6ce8\u91ca\u6765\u63cf\u8ff0 varargs \u53c2\u6570\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u901a\u8fc7 javadoc \u6ce8\u91ca\u6765\u63cf\u8ff0 varargs \u53c2\u6570\uff1f<\/h1>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u5c31\u6574\u7406\u5206\u4eab\u300a\u5982\u4f55\u901a\u8fc7 javadoc \u6ce8\u91ca\u6765\u63cf\u8ff0 varargs \u53c2\u6570\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729927003671c975bc0264.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 javadoc \u6ce8\u91ca\u63cf\u8ff0 varargs \u53c2\u6570<\/strong><\/p>\n<p>varargs \u53c2\u6570\u5728 Java \u4e2d\u7528\u4e8e\u8868\u793a\u53ef\u80fd\u4f20\u9012\u53ef\u53d8\u6570\u91cf\u7684\u53c2\u6570\u65b9\u6cd5\u3002\u8981\u4f7f\u7528 javadoc \u6ce8\u91ca\u6765\u63cf\u8ff0 varargs \u53c2\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>@param<\/code> \u6ce8\u91ca\uff0c\u540e\u9762\u8ddf\u4e0a <code>...<\/code> \u6765\u8868\u793a varargs \u90e8\u5206\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>\/**\n * \u8ba1\u7b97\u6570\u5b57\u6570\u7ec4\u7684\u5e73\u5747\u503c\u3002\n *\n * @param numbers \u8981\u8ba1\u7b97\u5e73\u5747\u503c\u7684\u6570\u5b57\n * @return \u6570\u5b57\u6570\u7ec4\u7684\u5e73\u5747\u503c\n *\/\npublic static double average(double... numbers) {\n    \/\/ \u8ba1\u7b97\u6570\u5b57\u6570\u7ec4\u7684\u603b\u548c\n    double sum = 0;\n    for (double number : numbers) {\n        sum += number;\n    }\n\n    \/\/ \u8fd4\u56de\u6570\u5b57\u6570\u7ec4\u7684\u5e73\u5747\u503c\n    return sum \/ numbers.length;\n}<\/pre>\n<p>\u5728\u4e0a\u9762\u793a\u4f8b\u4e2d\uff0c<code>average<\/code> \u65b9\u6cd5\u6709\u4e24\u4e2a\u53c2\u6570\uff1a\u4e00\u4e2a\u6ca1\u6709 varargs \u90e8\u5206\u7684\u6570\u5b57\u6570\u7ec4 <code>numbers<\/code> \u548c\u4e00\u4e2a varargs \u53c2\u6570 <code>...numbers<\/code>\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b9e\u6218\u6848\u4f8b\uff0c\u8bf4\u660e\u5982\u4f55\u4f7f\u7528 javadoc \u6ce8\u91ca\u6765\u63cf\u8ff0 varargs \u53c2\u6570\uff1a<\/p>\n<pre>\/**\n * \u8fde\u63a5\u4e24\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u4e32\u3002\n *\n * @param strings \u8981\u8fde\u63a5\u7684\u5b57\u7b26\u4e32\n * @return \u8fde\u63a5\u540e\u7684\u5b57\u7b26\u4e32\n *\/\npublic static String concatenate(String... strings) {\n    StringBuilder builder = new StringBuilder();\n    for (String string : strings) {\n        builder.append(string);\n    }\n\n    return builder.toString();\n}<\/pre>\n<p>\u5728\u4e0a\u9762\u793a\u4f8b\u4e2d\uff0c<code>concatenate<\/code> \u65b9\u6cd5\u6709\u4e00\u4e2a varargs \u53c2\u6570 <code>strings<\/code>\uff0c\u5b83\u53ef\u4ee5\u4f20\u9012\u53ef\u53d8\u6570\u91cf\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u5982\u4f55\u901a\u8fc7 javadoc \u6ce8\u91ca\u6765\u63cf\u8ff0 varargs \u53c2\u6570\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8eJavadoc,varargs\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u901a\u8fc7 javadoc \u6ce8\u91ca\u6765&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202641","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202641"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202641\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}