{"id":37358,"date":"2023-12-11T14:41:08","date_gmt":"2023-12-11T06:41:08","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=37358"},"modified":"2023-12-11T14:41:08","modified_gmt":"2023-12-11T06:41:08","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88java%e4%b8%ad%e5%8f%aa%e6%9c%89%e5%80%bc%e4%bc%a0%e9%80%92%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/%e4%b8%ba%e4%bb%80%e4%b9%88java%e4%b8%ad%e5%8f%aa%e6%9c%89%e5%80%bc%e4%bc%a0%e9%80%92%ef%bc%9f\/","title":{"rendered":"\u4e3a\u4ec0\u4e48Java\u4e2d\u53ea\u6709\u503c\u4f20\u9012\uff1f"},"content":{"rendered":"<p>&#8220;`&#8221;                    \u9996\u5148\u56de\u987e\u4e00\u4e0b\u5728\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u4e2d\u6709\u5173\u5c06\u53c2\u6570\u4f20\u9012\u7ed9\u65b9\u6cd5\uff08\u6216\u51fd\u6570\uff09\u7684\u4e00\u4e9b\u4e13\u4e1a\u672f\u8bed\u3002<strong>\u6309\u503c\u8c03\u7528(call by value)\u8868\u793a\u65b9\u6cd5\u63a5\u6536\u7684\u662f\u8c03\u7528\u8005\u63d0\u4f9b\u7684\u503c\uff0c\u800c\u6309\u5f15\u7528\u8c03\u7528\uff08call by reference)\u8868\u793a\u65b9\u6cd5\u63a5\u6536\u7684\u662f\u8c03\u7528\u8005\u63d0\u4f9b\u7684\u53d8\u91cf\u5730\u5740\u3002\u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u4fee\u6539\u4f20\u9012\u5f15\u7528\u6240\u5bf9\u5e94\u7684\u53d8\u91cf\u503c\uff0c\u800c\u4e0d\u80fd\u4fee\u6539\u4f20\u9012\u503c\u8c03\u7528\u6240\u5bf9\u5e94\u7684\u53d8\u91cf\u503c\u3002<\/strong>  \u5b83\u7528\u6765\u63cf\u8ff0\u5404\u79cd\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\uff08\u4e0d\u53ea\u662fJava)\u4e2d\u65b9\u6cd5\u53c2\u6570\u4f20\u9012\u65b9\u5f0f\u3002<\/p>\n<p><strong>Java\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u603b\u662f\u91c7\u7528\u6309\u503c\u8c03\u7528\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u65b9\u6cd5\u5f97\u5230\u7684\u662f\u6240\u6709\u53c2\u6570\u503c\u7684\u4e00\u4e2a\u62f7\u8d1d\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u65b9\u6cd5\u4e0d\u80fd\u4fee\u6539\u4f20\u9012\u7ed9\u5b83\u7684\u4efb\u4f55\u53c2\u6570\u53d8\u91cf\u7684\u5185\u5bb9\u3002<\/strong><\/p>\n<p><strong>\u4e0b\u9762\u901a\u8fc7 3 \u4e2a\u4f8b\u5b50\u6765\u7ed9\u5927\u5bb6\u8bf4\u660e<\/strong><\/p>\n<h3>example 1<\/h3>\n<p><code><\/code>`javapublic static void main(String[] args) {    int num1 = 10;    int num2 = 20;<\/p>\n<pre><code>swap(num1, num2);System.out.println(\"\"num1 = \"\" + num1);System.out.println(\"\"num2 = \"\" + num2);<\/code><\/pre>\n<p>}<\/p>\n<p>public static void swap(int a, int b) {    int temp = a;    a = b;    b = temp;<\/p>\n<pre><code>System.out.println(\"\"a = \"\" + a);System.out.println(\"\"b = \"\" + b);<\/code><\/pre>\n<p>}<code><\/code>`<\/p>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<p><code>a = 20b = 10num1 = 10num2 = 20<\/code><\/p>\n<p><strong>\u89e3\u6790\uff1a<\/strong><\/p>\n<p><img decoding=\"async\" alt=\"\"example 1 \"\" src=\"\"http:\/\/my-blog-to-use.oss-cn-beijing.aliyuncs.com\/18-9-27\/22191348.jpg\"\"><\/p>\n<p>\u5728swap\u65b9\u6cd5\u4e2d\uff0ca\u3001b\u7684\u503c\u8fdb\u884c\u4ea4\u6362\uff0c\u5e76\u4e0d\u4f1a\u5f71\u54cd\u5230 num1\u3001num2\u3002\u56e0\u4e3a\uff0ca\u3001b\u4e2d\u7684\u503c\uff0c\u53ea\u662f\u4ece num1\u3001num2 \u7684\u590d\u5236\u8fc7\u6765\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0ca\u3001b\u76f8\u5f53\u4e8enum1\u3001num2 \u7684\u526f\u672c\uff0c\u526f\u672c\u7684\u5185\u5bb9\u65e0\u8bba\u600e\u4e48\u4fee\u6539\uff0c\u90fd\u4e0d\u4f1a\u5f71\u54cd\u5230\u539f\u4ef6\u672c\u8eab\u3002<\/p>\n<p><strong>\u901a\u8fc7\u4e0a\u9762\u4f8b\u5b50\uff0c\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\u4e86\u4e00\u4e2a\u65b9\u6cd5\u4e0d\u80fd\u4fee\u6539\u4e00\u4e2a\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u800c\u5bf9\u8c61\u5f15\u7528\u4f5c\u4e3a\u53c2\u6570\u5c31\u4e0d\u4e00\u6837\uff0c\u8bf7\u770b example2.<\/strong><\/p>\n<h3>example 2<\/h3>\n<p><code><\/code>`java  public static void main(String[] args) {        int[] arr = { 1, 2, 3, 4, 5 };      System.out.println(arr[0]);     change(arr);        System.out.println(arr[0]); }<\/p>\n<pre><code>public static void change(int[] array) {\t\/\/ \u5c06\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u53d8\u4e3a0\tarray[0] = 0;}<\/code><\/pre>\n<p><code><\/code>`<\/p>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<p><code>10<\/code><\/p>\n<p><strong>\u89e3\u6790\uff1a<\/strong><\/p>\n<p><img decoding=\"async\" alt=\"\"example 2\"\" src=\"\"http:\/\/my-blog-to-use.oss-cn-beijing.aliyuncs.com\/18-9-27\/3825204.jpg\"\"><\/p>\n<p>array \u88ab\u521d\u59cb\u5316 arr \u7684\u62f7\u8d1d\u4e5f\u5c31\u662f\u4e00\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u4e5f\u5c31\u662f\u8bf4 array \u548c arr \u6307\u5411\u7684\u662f\u540c\u4e00\u4e2a\u6570\u7ec4\u5bf9\u8c61\u3002 \u56e0\u6b64\uff0c\u5916\u90e8\u5bf9\u5f15\u7528\u5bf9\u8c61\u7684\u6539\u53d8\u4f1a\u53cd\u6620\u5230\u6240\u5bf9\u5e94\u7684\u5bf9\u8c61\u4e0a\u3002<\/p>\n<p><strong>\u901a\u8fc7 example2 \u6211\u4eec\u5df2\u7ecf\u770b\u5230\uff0c\u5b9e\u73b0\u4e00\u4e2a\u6539\u53d8\u5bf9\u8c61\u53c2\u6570\u72b6\u6001\u7684\u65b9\u6cd5\u5e76\u4e0d\u662f\u4e00\u4ef6\u96be\u4e8b\u3002\u7406\u7531\u5f88\u7b80\u5355\uff0c\u65b9\u6cd5\u5f97\u5230\u7684\u662f\u5bf9\u8c61\u5f15\u7528\u7684\u62f7\u8d1d\uff0c\u5bf9\u8c61\u5f15\u7528\u53ca\u5176\u4ed6\u7684\u62f7\u8d1d\u540c\u65f6\u5f15\u7528\u540c\u4e00\u4e2a\u5bf9\u8c61\u3002<\/strong><\/p>\n<p><strong>\u5f88\u591a\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\uff08\u7279\u522b\u662f\uff0cC++\u548cPascal)\u63d0\u4f9b\u4e86\u4e24\u79cd\u53c2\u6570\u4f20\u9012\u7684\u65b9\u5f0f\uff1a\u503c\u8c03\u7528\u548c\u5f15\u7528\u8c03\u7528\u3002\u6709\u4e9b\u7a0b\u5e8f\u5458\uff08\u751a\u81f3\u672c\u4e66\u7684\u4f5c\u8005\uff09\u8ba4\u4e3aJava\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u5bf9\u5bf9\u8c61\u91c7\u7528\u7684\u662f\u5f15\u7528\u8c03\u7528\uff0c\u5b9e\u9645\u4e0a\uff0c\u8fd9\u79cd\u7406\u89e3\u662f\u4e0d\u5bf9\u7684\u3002\u7531\u4e8e\u8fd9\u79cd\u8bef\u89e3\u5177\u6709\u4e00\u5b9a\u7684\u666e\u904d\u6027\uff0c\u6240\u4ee5\u4e0b\u9762\u7ed9\u51fa\u4e00\u4e2a\u53cd\u4f8b\u6765\u8be6\u7ec6\u5730\u9610\u8ff0\u4e00\u4e0b\u8fd9\u4e2a\u95ee\u9898\u3002<\/strong><\/p>\n<h3>example 3<\/h3>\n<p><code><\/code>`javapublic class Test {<\/p>\n<pre><code>public static void main(String[] args) {\t\/\/ TODO Auto-generated method stub\tStudent s1 = new Student(\"\"\u5c0f\u5f20\"\");\tStudent s2 = new Student(\"\"\u5c0f\u674e\"\");\tTest.swap(s1, s2);\tSystem.out.println(\"\"s1:\"\" + s1.getName());\tSystem.out.println(\"\"s2:\"\" + s2.getName());}public static void swap(Student x, Student y) {\tStudent temp = x;\tx = y;\ty = temp;\tSystem.out.println(\"\"x:\"\" + x.getName());\tSystem.out.println(\"\"y:\"\" + y.getName());}<\/code><\/pre>\n<p>}<code><\/code>`<\/p>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<p><code>x:\u5c0f\u674ey:\u5c0f\u5f20s1:\u5c0f\u5f20s2:\u5c0f\u674e<\/code><\/p>\n<p><strong>\u89e3\u6790\uff1a<\/strong><\/p>\n<p>\u4ea4\u6362\u4e4b\u524d\uff1a<\/p>\n<p><img decoding=\"async\" alt=\"\"\"\" src=\"\"http:\/\/my-blog-to-use.oss-cn-beijing.aliyuncs.com\/18-9-27\/88729818.jpg\"\"><\/p>\n<p>\u4ea4\u6362\u4e4b\u540e\uff1a<\/p>\n<p><img decoding=\"async\" alt=\"\"\"\" src=\"\"http:\/\/my-blog-to-use.oss-cn-beijing.aliyuncs.com\/18-9-27\/34384414.jpg\"\"><\/p>\n<p>\u901a\u8fc7\u4e0a\u9762\u4e24\u5f20\u56fe\u53ef\u4ee5\u5f88\u6e05\u6670\u7684\u770b\u51fa\uff1a <strong>\u65b9\u6cd5\u5e76\u6ca1\u6709\u6539\u53d8\u5b58\u50a8\u5728\u53d8\u91cf s1 \u548c s2 \u4e2d\u7684\u5bf9\u8c61\u5f15\u7528\u3002swap\u65b9\u6cd5\u7684\u53c2\u6570x\u548cy\u88ab\u521d\u59cb\u5316\u4e3a\u4e24\u4e2a\u5bf9\u8c61\u5f15\u7528\u7684\u62f7\u8d1d\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u4ea4\u6362\u7684\u662f\u8fd9\u4e24\u4e2a\u62f7\u8d1d<\/strong><\/p>\n<h3>\u603b\u7ed3<\/h3>\n<p>Java\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u5bf9\u5bf9\u8c61\u91c7\u7528\u7684\u4e0d\u662f\u5f15\u7528\u8c03\u7528\uff0c\u5b9e\u9645\u4e0a\uff0c\u5bf9\u8c61\u5f15\u7528\u662f\u6309\u503c\u4f20\u9012\u7684\u3002<\/p>\n<p>\u4e0b\u9762\u518d\u603b\u7ed3\u4e00\u4e0bJava\u4e2d\u65b9\u6cd5\u53c2\u6570\u7684\u4f7f\u7528\u60c5\u51b5\uff1a<\/p>\n<ul>\n<li>\u4e00\u4e2a\u65b9\u6cd5\u4e0d\u80fd\u4fee\u6539\u4e00\u4e2a\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u53c2\u6570\uff08\u5373\u6570\u503c\u578b\u6216\u5e03\u5c14\u578b\uff09\u3002<\/li>\n<li>\u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u6539\u53d8\u4e00\u4e2a\u5bf9\u8c61\u53c2\u6570\u7684\u72b6\u6001\u3002<\/li>\n<li>\u4e00\u4e2a\u65b9\u6cd5\u4e0d\u80fd\u8ba9\u5bf9\u8c61\u53c2\u6570\u5f15\u7528\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<pre><code>            \"```\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; \u9996\u5148\u56de\u987e\u4e00\u4e0b\u5728\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u4e2d\u6709\u5173\u5c06\u53c2\u6570\u4f20\u9012\u7ed9\u65b9\u6cd5\uff08\u6216\u51fd\u6570\uff09\u7684\u4e00\u4e9b\u4e13\u4e1a\u672f\u8bed\u3002\u6309\u503c [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-37358","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=37358"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37358\/revisions"}],"predecessor-version":[{"id":37359,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37358\/revisions\/37359"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=37358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=37358"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=37358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}