{"id":202703,"date":"2025-05-22T11:08:52","date_gmt":"2025-05-22T03:08:52","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202703\/"},"modified":"2025-05-22T11:08:52","modified_gmt":"2025-05-22T03:08:52","slug":"java-%e6%96%b9%e6%b3%95%e4%b8%ad%e5%8f%82%e6%95%b0%e4%bc%a0%e9%80%92%e5%80%bc%e6%97%b6%e7%9a%84%e5%ae%9e%e9%99%85%e6%93%8d%e4%bd%9c%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202703\/","title":{"rendered":"Java \u65b9\u6cd5\u4e2d\u53c2\u6570\u4f20\u9012\u503c\u65f6\u7684\u5b9e\u9645\u64cd\u4f5c\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Java \u65b9\u6cd5\u4e2d\u53c2\u6570\u4f20\u9012\u503c\u65f6\u7684\u5b9e\u9645\u64cd\u4f5c\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>\u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aJava \u65b9\u6cd5\u4e2d\u53c2\u6570\u4f20\u9012\u503c\u65f6\u7684\u5b9e\u9645\u64cd\u4f5c\u662f\u4ec0\u4e48\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<p>Java\u65b9\u6cd5\u4e2d\u53c2\u6570\u4f20\u9012\u503c\u65f6\u6309\u503c\u4f20\u9012\u57fa\u672c\u7c7b\u578b\uff08\u5982int\uff09\uff0c\u6309\u5f15\u7528\u4f20\u9012\u5f15\u7528\u7c7b\u578b\uff08\u5982\u5bf9\u8c61\u548c\u6570\u7ec4\uff09\u3002\u82e5\u6309\u503c\u4f20\u9012\uff0c\u4fee\u6539\u65b9\u6cd5\u4e2d\u526f\u672c\u7684\u503c\u4e0d\u5f71\u54cd\u539f\u59cb\u503c\uff1b\u82e5\u6309\u5f15\u7528\u4f20\u9012\uff0c\u4fee\u6539\u65b9\u6cd5\u4e2d\u5f15\u7528\u5bf9\u8c61\u7684\u503c\u4f1a\u5f71\u54cd\u539f\u59cb\u5bf9\u8c61\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729934448671cb470e87e1.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>Java \u65b9\u6cd5\u4e2d\u53c2\u6570\u4f20\u9012\u503c\u65f6\u7684\u5b9e\u9645\u64cd\u4f5c<\/strong><\/p>\n<p>\u5728 Java \u65b9\u6cd5\u4e2d\uff0c\u53c2\u6570\u4f20\u9012\u503c\u65f6\u53d1\u751f\u4e86\u4ee5\u4e0b\u5b9e\u9645\u64cd\u4f5c\uff1a<\/p>\n<p><strong>\u6309\u503c\u4f20\u9012\uff1a<\/strong><\/p>\n<p>\u5f53\u503c\u7c7b\u578b\uff08int\u3001double \u7b49\uff09\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u65f6\uff0c\u4f1a\u521b\u5efa\u5b9e\u9645\u503c\u7684\u526f\u672c\u5e76\u5c06\u5176\u4f20\u9012\u7ed9\u65b9\u6cd5\u3002\u8fd9\u610f\u5473\u7740\u5bf9\u65b9\u6cd5\u4e2d\u526f\u672c\u7684\u66f4\u6539\u4e0d\u4f1a\u5f71\u54cd\u8c03\u7528\u65b9\u6cd5\u4e2d\u7684\u539f\u59cb\u503c\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>public class ValuePassExample {\n\n    public static void main(String[] args) {\n        int n = 10;\n        increment(n);\n        System.out.println(n); \/\/ \u8f93\u51fa: 10\n    }\n\n    public static void increment(int n) {\n        n++;\n    }\n}<\/pre>\n<p><strong>\u6309\u5f15\u7528\u4f20\u9012\uff1a<\/strong><\/p>\n<p>\u5f53\u5f15\u7528\u7c7b\u578b\uff08\u5bf9\u8c61\u548c\u6570\u7ec4\uff09\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u65f6\uff0c\u4f20\u9012\u7684\u662f\u539f\u59cb\u503c\u7684\u5f15\u7528\uff08\u5185\u5b58\u5730\u5740\uff09\u3002\u8fd9\u610f\u5473\u7740\u5bf9\u65b9\u6cd5\u4e2d\u5f15\u7528\u5bf9\u8c61\u7684\u66f4\u6539\u5c06\u53cd\u6620\u5728\u8c03\u7528\u65b9\u6cd5\u4e2d\u7684\u539f\u59cb\u5bf9\u8c61\u4e2d\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>public class RefPassExample {\n\n    public static void main(String[] args) {\n        Person p = new Person(\"John\");\n        changeName(p);\n        System.out.println(p.getName()); \/\/ \u8f93\u51fa: Alice\n    }\n\n    public static void changeName(Person p) {\n        p.setName(\"Alice\");\n    }\n\n    private static class Person {\n        private String name;\n\n        public Person(String name) {\n            this.name = name;\n        }\n\n        public String getName() {\n            return name;\n        }\n\n        public void setName(String name) {\n            this.name = name;\n        }\n    }\n}<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aJava \u65b9\u6cd5\u4e2d\u53c2\u6570\u4f20\u9012\u503c\u65f6\u7684\u5b9e\u9645\u64cd\u4f5c\u662f\u4ec0\u4e48\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java \u65b9\u6cd5\u4e2d\u53c2\u6570\u4f20\u9012\u503c\u65f6\u7684\u5b9e&#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-202703","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202703","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=202703"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202703\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}