{"id":201904,"date":"2020-10-08T08:09:07","date_gmt":"2020-10-08T00:09:07","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=201904"},"modified":"2020-09-25T13:11:59","modified_gmt":"2020-09-25T05:11:59","slug":"teach-you-to-9","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/teach-you-to-9.html","title":{"rendered":"\u6559\u4f60\u8ba4\u8bc6Java \u53ef\u53d8\u53c2\u6570"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728 Java 5 \u4e2d\u63d0\u4f9b\u4e86\u53d8\u957f\u53c2\u6570\uff0c\u5141\u8bb8\u5728\u8c03\u7528\u65b9\u6cd5\u65f6\u4f20\u5165\u4e0d\u5b9a\u957f\u5ea6\u7684\u53c2\u6570\u3002\u53d8\u957f\u53c2\u6570\u662f Java \u7684\u4e00\u4e2a\u8bed\u6cd5\u7cd6\uff0c\u672c\u8d28\u4e0a\u8fd8\u662f\u57fa\u4e8e\u6570\u7ec4\u7684\u5b9e\u73b0\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u6570\u7ec4\u7684\u5b9e\u73b0\uff1a<\/p>\n

void foo(String... args);\r\nvoid foo(String[] args);<\/pre>\n
\/\/\u65b9\u6cd5\u7b7e\u540d \r\n([Ljava\/lang\/String;)V \/\/ public void foo(String[] args)<\/pre>\n
\u5b9a\u4e49\u65b9\u6cd5<\/strong><\/div>\n

\u5728\u5b9a\u4e49\u65b9\u6cd5\u65f6\uff0c\u5728\u6700\u540e\u4e00\u4e2a\u5f62\u53c2\u540e\u52a0\u4e0a\u4e09\u70b9 \u2026\uff0c\u5c31\u8868\u793a\u8be5\u5f62\u53c2\u53ef\u4ee5\u63a5\u53d7\u591a\u4e2a\u53c2\u6570\u503c\uff0c\u591a\u4e2a\u53c2\u6570\u503c\u88ab\u5f53\u6210\u6570\u7ec4\u4f20\u5165\u3002\u4e0a\u8ff0\u5b9a\u4e49\u6709\u51e0\u4e2a\u8981\u70b9\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n

    \n
  1. \u53ef\u53d8\u53c2\u6570\u53ea\u80fd\u4f5c\u4e3a\u51fd\u6570\u7684\u6700\u540e\u4e00\u4e2a\u53c2\u6570\uff0c\u4f46\u5176\u524d\u9762\u53ef\u4ee5\u6709\u4e5f\u53ef\u4ee5\u6ca1\u6709\u4efb\u4f55\u5176\u4ed6\u53c2\u6570<\/li>\n
  2. \u7531\u4e8e\u53ef\u53d8\u53c2\u6570\u5fc5\u987b\u662f\u6700\u540e\u4e00\u4e2a\u53c2\u6570\uff0c\u6240\u4ee5\u4e00\u4e2a\u51fd\u6570\u6700\u591a\u53ea\u80fd\u6709\u4e00\u4e2a\u53ef\u53d8\u53c2\u6570<\/li>\n
  3. Java\u7684\u53ef\u53d8\u53c2\u6570\uff0c\u4f1a\u88ab\u7f16\u8bd1\u5668\u8f6c\u578b\u4e3a\u4e00\u4e2a\u6570\u7ec4<\/li>\n
  4. \u53d8\u957f\u53c2\u6570\u5728\u7f16\u8bd1\u4e3a\u5b57\u8282\u7801\u540e\uff0c\u5728\u65b9\u6cd5\u7b7e\u540d\u4e2d\u5c31\u662f\u4ee5\u6570\u7ec4\u5f62\u6001\u51fa\u73b0\u7684\u3002\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u7684\u7b7e\u540d\u662f\u4e00\u81f4\u7684\uff0c\u4e0d\u80fd\u4f5c\u4e3a\u65b9\u6cd5\u7684\u91cd\u8f7d\u3002\u5982\u679c\u540c\u65f6\u51fa\u73b0\uff0c\u662f\u4e0d\u80fd\u7f16\u8bd1\u901a\u8fc7\u7684\u3002\u53ef\u53d8\u53c2\u6570\u53ef\u4ee5\u517c\u5bb9\u6570\u7ec4\uff0c\u53cd\u4e4b\u5219\u4e0d\u6210\u7acb<\/li>\n<\/ol>\n
    public void foo(String...varargs){}\r\n\r\nfoo(\"arg1\", \"arg2\", \"arg3\");\r\n\r\n\/\/\u4e0a\u8ff0\u8fc7\u7a0b\u548c\u4e0b\u9762\u7684\u8c03\u7528\u662f\u7b49\u4ef7\u7684\r\nfoo(new String[]{\"arg1\", \"arg2\", \"arg3\"});<\/pre>\n

    J2SE 1.5 \u4e2d\u65b0\u589e\u4e86\"\u6cdb\u578b\"\u7684\u673a\u5236\uff0c\u53ef\u4ee5\u5728\u4e00\u5b9a\u6761\u4ef6\u4e0b\u628a\u4e00\u4e2a\u7c7b\u578b\u53c2\u6570\u5316\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u7f16\u5199\u4e00\u4e2a\u7c7b\u7684\u65f6\u5019\uff0c\u628a\u4e00\u4e2a\u65b9\u6cd5\u7684\u5f62\u53c2\u7684\u7c7b\u578b\u7528\u4e00\u4e2a\u6807\u8bc6\u7b26\uff08\u5982T\uff09\u6765\u4ee3\u8868\uff0c \u81f3\u4e8e\u8fd9\u4e2a\u6807\u8bc6\u7b26\u5230\u5e95\u8868\u793a\u4ec0\u4e48\u7c7b\u578b\uff0c\u5219\u5728\u751f\u6210\u8fd9\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u7684\u65f6\u5019\u518d\u884c\u6307\u5b9a\u3002\u8fd9\u4e00\u673a\u5236\u53ef\u4ee5\u7528\u6765\u63d0\u4f9b\u66f4\u5145\u5206\u7684\u4ee3\u7801\u91cd\u7528\u548c\u66f4\u4e25\u683c\u7684\u7f16\u8bd1\u65f6\u7c7b\u578b\u68c0\u67e5\u3002\u4e0d\u8fc7\u6cdb\u578b\u673a\u5236\u5374\u4e0d\u80fd\u548c\u4e2a\u6570\u53ef\u53d8\u7684\u5f62\u53c2\u914d\u5408\u4f7f\u7528\u3002\u5982\u679c\u628a\u4e00\u4e2a\u80fd\u548c\u4e0d\u786e\u5b9a\u4e2a\u5b9e\u53c2\u76f8\u5339\u914d\u7684\u5f62\u53c2\u7684\u7c7b\u578b\uff0c\u7528\u4e00\u4e2a\u6807\u8bc6\u7b26\u6765\u4ee3\u8868\uff0c\u90a3\u4e48\u7f16\u8bd1\u5668\u4f1a\u7ed9\u51fa\u4e00\u4e2a \"generic array creation\"<\/strong> \u7684\u9519\u8bef\u3002<\/p>\n

    public class Varargs {\r\n\r\n    public static void test(String... args) {\r\n        for(String arg : args) {\/\/\u5f53\u4f5c\u6570\u7ec4\u7528foreach\u904d\u5386\r\n            System.out.println(arg);\r\n        }\r\n    }\r\n    \/\/Compile error\r\n    \/\/The variable argument type Object of the method must be the last parameter\r\n    \/\/public void error1(String... args, Object o) {}\r\n    \/\/public void error2(String... args, Integer... i) {}\r\n\r\n    \/\/Compile error\r\n    \/\/Duplicate method test(String...) in type Varargs\r\n    \/\/public void test(String[] args){}\r\n}<\/pre>\n
    \u53ef\u53d8\u53c2\u6570\u65b9\u6cd5\u7684\u8c03\u7528<\/strong><\/div>\n

    \u8c03\u7528\u53ef\u53d8\u53c2\u6570\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7ed9\u51fa\u96f6\u5230\u4efb\u610f\u591a\u4e2a\u53c2\u6570\uff0c\u7f16\u8bd1\u5668\u4f1a\u5c06\u53ef\u53d8\u53c2\u6570\u8f6c\u5316\u4e3a\u4e00\u4e2a\u6570\u7ec4\u3002\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f20\u9012\u4e00\u4e2a\u6570\u7ec4\uff0c\u793a\u4f8b\u5982\u4e0b:<\/p>\n

    public class Varargs {\r\n\r\n    public static void test(String... args) {\r\n        for(String arg : args) {\r\n            System.out.println(arg);\r\n        }\r\n    }\r\n\r\n    public static void main(String[] args) {\r\n        test();\/\/0\u4e2a\u53c2\u6570\r\n        test(\"a\");\/\/1\u4e2a\u53c2\u6570\r\n        test(\"a\",\"b\");\/\/\u591a\u4e2a\u53c2\u6570\r\n        test(new String[] {\"a\", \"b\", \"c\"});\/\/\u76f4\u63a5\u4f20\u9012\u6570\u7ec4\r\n    }\r\n}<\/pre>\n
    \u65b9\u6cd5\u91cd\u8f7d<\/strong><\/div>\n
    \u4f18\u5148\u5339\u914d\u56fa\u5b9a\u53c2\u6570<\/strong><\/span><\/div>\n

    \u8c03\u7528\u4e00\u4e2a\u88ab\u91cd\u8f7d\u7684\u65b9\u6cd5\u65f6\uff0c\u5982\u679c\u6b64\u8c03\u7528\u65e2\u80fd\u591f\u548c\u56fa\u5b9a\u53c2\u6570\u7684\u91cd\u8f7d\u65b9\u6cd5\u5339\u914d\uff0c\u4e5f\u80fd\u591f\u4e0e\u53ef\u53d8\u957f\u53c2\u6570\u7684\u91cd\u8f7d\u65b9\u6cd5\u5339\u914d\uff0c\u5219\u9009\u62e9\u56fa\u5b9a\u53c2\u6570\u7684\u65b9\u6cd5:<\/p>\n

    public class Varargs {\r\n\r\n    public static void test(String... args) {\r\n        System.out.println(\"version 1\");\r\n    }\r\n\r\n    public static void test(String arg1, String arg2) {\r\n        System.out.println(\"version 2\");\r\n    }\r\n    public static void main(String[] args) {\r\n        test(\"a\",\"b\");\/\/version 2 \u4f18\u5148\u5339\u914d\u56fa\u5b9a\u53c2\u6570\u7684\u91cd\u8f7d\u65b9\u6cd5\r\n                test();\/\/version 1\r\n    }\r\n}<\/pre>\n
    >\u5339\u914d\u591a\u4e2a\u53ef\u53d8\u53c2\u6570<\/strong><\/span><\/div>\n

    \u8c03\u7528\u4e00\u4e2a\u88ab\u91cd\u8f7d\u7684\u65b9\u6cd5\u65f6\uff0c\u5982\u679c\u6b64\u8c03\u7528\u65e2\u80fd\u591f\u548c\u4e24\u4e2a\u53ef\u53d8\u957f\u53c2\u6570\u7684\u91cd\u8f7d\u65b9\u6cd5\u5339\u914d\uff0c\u5219\u7f16\u8bd1\u51fa\u9519:<\/p>\n

    public class Varargs {\r\n\r\n    public static void test(String... args) {\r\n        System.out.println(\"version 1\");\r\n    }\r\n\r\n    public static void test(String arg1, String... arg2) {\r\n        System.out.println(\"version 2\");\r\n    }\r\n    public static void main(String[] args) {\r\n        test(\"a\",\"b\");\/\/Compile error\r\n    }\r\n}<\/pre>\n
    \u65b9\u6cd5\u91cd\u5199<\/strong><\/div>\n
    \u907f\u514d\u5e26\u6709\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5\u91cd\u8f7d<\/strong><\/span><\/div>\n

    \u5373\u4fbf\u7f16\u8bd1\u5668\u53ef\u4ee5\u6309\u7167\u4f18\u5148\u5339\u914d\u56fa\u5b9a\u53c2\u6570\u7684\u65b9\u5f0f\u786e\u5b9a\u5177\u4f53\u7684\u8c03\u7528\u65b9\u6cd5\uff0c\u4f46\u5728\u9605\u8bfb\u4ee3\u7801\u7684\u4f9d\u7136\u5bb9\u6613\u6389\u5165\u9677\u9631\u3002\u8981\u614e\u91cd\u8003\u8651\u53d8\u957f\u53c2\u6570\u7684\u65b9\u6cd5\u91cd\u8f7d\u3002<\/p>\n

    \u522b\u8ba9 null \u503c\u548c\u7a7a\u503c\u5a01\u80c1\u5230\u53d8\u957f\u65b9\u6cd5<\/strong><\/span><\/div>\n
    public class Client {  \r\n     public void methodA(String str,Integer... is){       \r\n     }  \r\n\r\n     public void methodA(String str,String... strs){          \r\n     }  \r\n\r\n     public static void main(String[] args) {  \r\n           Client client = new Client();  \r\n           client.methodA(\"China\", 0);  \r\n           client.methodA(\"China\", \"People\");  \r\n           client.methodA(\"China\");  \/\/compile error\r\n           client.methodA(\"China\",null);  \/\/compile error\r\n     }  \r\n}<\/pre>\n

    \u4fee\u6539\u5982\u4e0b\uff1a<\/p>\n

    public static void main(String[] args) {  \r\n     Client client = new Client();  \r\n     String[] strs = null;  \r\n     client.methodA(\"China\",strs);  \r\n}<\/pre>\n

    \u8ba9\u7f16\u8bd1\u5668\u77e5\u9053\u8fd9\u4e2anull\u503c\u662fString\u7c7b\u578b\u7684\uff0c\u7f16\u8bd1\u5373\u53ef\u987a\u5229\u901a\u8fc7\uff0c\u4e5f\u5c31\u51cf\u5c11\u4e86\u9519\u8bef\u7684\u53d1\u751f\u3002<\/p>\n

    \u8986\u5199\u53d8\u957f\u65b9\u6cd5\u4e5f\u8981\u5faa\u89c4\u8e48\u77e9<\/strong><\/span><\/div>\n
    package com;\r\npublic class VarArgsTest2 {\r\n    \/**\r\n     * @param args\r\n     *\/\r\n    public static void main(String[] args) {\r\n        \/\/ TODO Auto-generated method stub\r\n        \/\/ \u5411\u4e0a\u8f6c\u578b\r\n        Base base = new Sub();\r\n        base.print(\"hello\");\r\n        \/\/ \u4e0d\u8f6c\u578b\r\n        Sub sub = new Sub();\r\n        sub.print(\"hello\");\/\/compile error\r\n    }\r\n}\r\n\/\/ \u57fa\u7c7b\r\nclass Base {\r\n    void print(String... args) {\r\n        System.out.println(\"Base......test\");\r\n    }\r\n}\r\n\/\/ \u5b50\u7c7b\uff0c\u8986\u5199\u7236\u7c7b\u65b9\u6cd5\r\nclass Sub extends Base {\r\n    @Override\r\n    void print(String[] args) {\r\n        System.out.println(\"Sub......test\");\r\n    }\r\n}<\/pre>\n

    \u7b2c\u4e00\u4e2a\u80fd\u7f16\u8bd1\u901a\u8fc7\uff0c\u8fd9\u662f\u4e3a\u4ec0\u4e48\u5462\uff1f\u4e8b\u5b9e\u4e0a\uff0cbase \u5bf9\u8c61\u628a\u5b50\u7c7b\u5bf9\u8c61 sub \u505a\u4e86\u5411\u4e0a\u8f6c\u578b\uff0c\u5f62\u53c2\u5217\u8868\u662f\u7531\u7236\u7c7b\u51b3\u5b9a\u7684\uff0c\u5f53\u7136\u80fd\u901a\u8fc7\u3002\u800c\u770b\u770b\u5b50\u7c7b\u76f4\u63a5\u8c03\u7528\u7684\u60c5\u51b5\uff0c\u8fd9\u65f6\u7f16\u8bd1\u5668\u770b\u5230\u5b50\u7c7b\u8986\u5199\u4e86\u7236\u7c7b\u7684 print \u65b9\u6cd5\uff0c\u56e0\u6b64\u80af\u5b9a\u4f7f\u7528\u5b50\u7c7b\u91cd\u65b0\u5b9a\u4e49\u7684 print \u65b9\u6cd5\uff0c\u5c3d\u7ba1\u53c2\u6570\u5217\u8868\u4e0d\u5339\u914d\u4e5f\u4e0d\u4f1a\u8dd1\u5230\u7236\u7c7b\u518d\u53bb\u5339\u914d\u4e0b\uff0c\u56e0\u4e3a\u627e\u5230\u4e86\u5c31\u4e0d\u518d\u627e\u4e86\uff0c\u56e0\u6b64\u6709\u4e86\u7c7b\u578b\u4e0d\u5339\u914d\u7684\u9519\u8bef\u3002<\/p>\n

    \u8fd9\u662f\u4e2a\u7279\u4f8b\uff0c\u8986\u5199\u7684\u65b9\u6cd5\u53c2\u6570\u5217\u8868\u7adf\u7136\u53ef\u4ee5\u4e0e\u7236\u7c7b\u4e0d\u76f8\u540c\uff0c\u8fd9\u8fdd\u80cc\u4e86\u8986\u5199\u7684\u5b9a\u4e49\uff0c\u5e76\u4e14\u4f1a\u5f15\u53d1\u83ab\u540d\u5176\u5999\u7684\u9519\u8bef\u3002<\/p>\n

    \u8fd9\u91cc\uff0c\u603b\u7ed3\u4e0b\u8986\u5199\u5fc5\u987b\u6ee1\u8db3\u7684\u6761\u4ef6\uff1a<\/p>\n

      \n
    1. \u8986\u5199\u65b9\u6cd5\u4e0d\u80fd\u7f29\u5c0f\u8bbf\u95ee\u6743\u9650<\/li>\n
    2. \u53c2\u6570\u5217\u8868\u5fc5\u987b\u4e0e\u88ab\u8986\u5199\u65b9\u6cd5\u76f8\u540c\uff08\u5305\u62ec\u663e\u793a\u5f62\u5f0f\uff09<\/li>\n
    3. \u8fd4\u56de\u7c7b\u578b\u5fc5\u987b\u4e0e\u88ab\u8986\u5199\u65b9\u6cd5\u7684\u76f8\u540c\u6216\u662f\u5176\u5b50\u7c7b<\/li>\n
    4. \u8986\u5199\u65b9\u6cd5\u4e0d\u80fd\u629b\u51fa\u65b0\u7684\u68c0\u67e5\u5f02\u5e38\uff0c\u6216\u8005\u8d85\u51fa\u7236\u7c7b\u8303\u56f4\u7684\u5f02\u5e38\uff0c\u4f46\u662f\u53ef\u4ee5\u629b\u51fa\u66f4\u5c11\u3001\u66f4\u6709\u9650\u7684\u5f02\u5e38\uff0c\u6216\u8005\u4e0d\u629b\u51fa\u5f02\u5e38<\/li>\n<\/ol>\n
      \u53ef\u80fd\u51fa\u73b0\u7684\u95ee\u9898<\/strong><\/div>\n

      \u4f7f\u7528 Object\u2026 \u4f5c\u4e3a\u53d8\u957f\u53c2\u6570\uff1a<\/p>\n

      public void foo(Object... args) {\r\n    System.out.println(args.length);\r\n}\r\n\r\nfoo(new String[]{\"arg1\", \"arg2\", \"arg3\"}); \/\/3\r\nfoo(100, new String[]{\"arg1\", \"arg1\"}); \/\/2\r\n\r\nfoo(new Integer[]{1, 2, 3}); \/\/3\r\nfoo(100, new Integer[]{1, 2, 3}); \/\/2\r\nfoo(1, 2, 3); \/\/3\r\nfoo(new int[]{1, 2, 3}); \/\/1<\/pre>\n

      int[] \u65e0\u6cd5\u8f6c\u578b\u4e3a Object[], \u56e0\u800c\u88ab\u5f53\u4f5c\u4e00\u4e2a\u5355\u7eaf\u7684\u6570\u7ec4\u5bf9\u8c61 ; Integer[] \u53ef\u4ee5\u8f6c\u578b\u4e3a Object[], \u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u5bf9\u8c61\u6570\u7ec4\u3002<\/p>\n

      \u53cd\u5c04\u65b9\u6cd5\u8c03\u7528\u65f6\u7684\u6ce8\u610f\u4e8b\u9879<\/strong><\/div>\n
      public class Test {\r\n    public static void foo(String... varargs){\r\n        System.out.println(args.length);\r\n    }\r\n\r\n    public static void main(String[] args){\r\n        String[] varArgs = new String[]{\"arg1\", \"arg2\"};\r\n        try{\r\n            Method method = Test.class.getMethod(\"foo\", String[].class);\r\n            method.invoke(null, varArgs);\r\n            method.invoke(null, (Object[])varArgs);\r\n            method.invoke(null, (Object)varArgs);\r\n            method.invoke(null, new Object[]{varArgs});\r\n        } catch (Exception e){\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n}<\/pre>\n

      \u4e0a\u9762\u7684\u56db\u4e2a\u8c03\u7528\u4e2d\uff0c\u524d\u4e24\u4e2a\u90fd\u4f1a\u5728\u8fd0\u884c\u65f6\u629b\u51fa java.lang.IllegalArgumentException: wrong number of arguments \u5f02\u5e38\uff0c\u540e\u4e24\u4e2a\u5219\u6b63\u5e38\u8c03\u7528\u3002<\/p>\n

      \u53cd\u5c04\u662f\u8fd0\u884c\u65f6\u83b7\u53d6\u7684\uff0c\u5728\u8fd0\u884c\u65f6\u770b\u6765\uff0c\u53ef\u53d8\u957f\u53c2\u6570\u548c\u6570\u7ec4\u662f\u4e00\u81f4\u7684\uff0c\u56e0\u800c\u65b9\u6cd5\u7b7e\u540d\u4e3a\uff1a<\/p>\n

      \/\/\u65b9\u6cd5\u7b7e\u540d\r\n([Ljava\/lang\/String;)V \/\/ public void foo(String[] varargs)<\/pre>\n

      \u518d\u6765\u770b\u4e00\u4e0b Method \u5bf9\u8c61\u7684\u65b9\u6cd5\u58f0\u660e\uff1a<\/p>\n

      Object invoke(Object obj, Object... args)<\/pre>\n

      args \u867d\u7136\u662f\u4e00\u4e2a\u53ef\u53d8\u957f\u5ea6\u7684\u53c2\u6570\uff0c\u4f46\u662f args \u7684\u957f\u5ea6\u662f\u53d7\u9650\u4e8e\u8be5\u65b9\u6cd5\u5bf9\u8c61\u4ee3\u8868\u7684\u771f\u5b9e\u65b9\u6cd5\u7684\u53c2\u6570\u5217\u8868\u957f\u5ea6\u7684\uff0c\u800c\u4ece\u8fd0\u884c\u65f6\u7b7e\u540d\u6765\u770b\uff0c([Ljava\/lang\/String;)V \u5b9e\u9645\u4e0a\u53ea\u6709\u4e00\u4e2a\u5f62\u53c2\uff0c\u5373 String[] varargs\uff0c\u56e0\u800c invoke(Object obj, Object\u2026 args) \u4e2d\u53ef\u53d8\u53c2\u6570 args \u7684\u5b9e\u53c2\u957f\u5ea6\u53ea\u80fd\u4e3a1<\/p>\n

      \/\/Object invoke(Object obj, Object... args)\r\n\/\/String[] varArgs = new String[]{\"arg1\", \"arg2\"};\r\nmethod.invoke(null, varArgs); \/\/varArgs\u957f\u5ea6\u4e3a2\uff0c\u9519\u8bef\r\nmethod.invoke(null, (Object[])varArgs); \/\/\u5c06String[]\u8f6c\u6362\u4e3aObject[],\u957f\u5ea6\u4e3a2\u7684\uff0c\u9519\u8bef\r\nmethod.invoke(null, (Object)varArgs);\/\/\u5c06\u6574\u4e2aString[] \u8f6c\u4e3aObject\uff0c\u957f\u5ea6\u4e3a1\uff0c\u7b26\u5408\r\nmethod.invoke(null, new Object[]{varArgs});\/\/Object[]\u957f\u5ea6\u4e3a1\uff0c\u6b63\u786e\u3002\u4e0a\u4e00\u4e2a\u548c\u8fd9\u4e2a\u662f\u7b49\u4ef7\u7684<\/pre>\n
      \u4ec0\u4e48\u65f6\u5019\u4f7f\u7528\u53ef\u53d8\u957f\u53c2\u6570\uff1f<\/strong><\/div>\n

      Stack Overflow \u4e0a\u6709\u4e2a\u5173\u4e8e\u53d8\u957f\u53c2\u6570\u4f7f\u7528\u7684\u95ee\u9898\u3002\u7b80\u5355\u5730\u8bf4\uff0c
      \n\u5728\u4e0d\u786e\u5b9a\u65b9\u6cd5\u9700\u8981\u5904\u7406\u7684\u5bf9\u8c61\u7684\u6570\u91cf\u65f6\u53ef\u4ee5\u4f7f\u7528\u53ef\u53d8\u957f\u53c2\u6570\uff0c\u4f1a\u4f7f\u5f97\u65b9\u6cd5\u8c03\u7528\u66f4\u7b80\u5355\uff0c\u65e0\u9700\u624b\u52a8\u521b\u5efa\u6570\u7ec4 new T[]{\u2026}<\/p>\n","protected":false},"excerpt":{"rendered":"

      \u6570\u7ec4\u7684\u5b9e\u73b0\uff1a void foo(String… args); void foo(String[] args […]<\/p>\n","protected":false},"author":321,"featured_media":201906,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-201904","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=201904"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201904\/revisions"}],"predecessor-version":[{"id":201908,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201904\/revisions\/201908"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/201906"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=201904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=201904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=201904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}