{"id":13092,"date":"2023-10-30T14:44:26","date_gmt":"2023-10-30T06:44:26","guid":{"rendered":"https:\/\/92it.top\/?p=13092"},"modified":"2023-10-30T14:44:26","modified_gmt":"2023-10-30T06:44:26","slug":"java-%e5%bc%95%e7%94%a8%e4%bc%a0%e9%80%92%ef%bc%9f%e5%80%bc%e4%bc%a0%e9%80%92%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=13092","title":{"rendered":"Java \u5f15\u7528\u4f20\u9012\uff1f\u503c\u4f20\u9012\uff1f"},"content":{"rendered":"\n<p>\u5f15\u7528\u4f20\u9012\u548c\u503c\u4f20\u9012\uff0c\u4ece\u4e0a\u5b66\u90a3\u4f1a\u513f\u5c31\u5f00\u59cb\u5f3a\u8c03\u7684\u6982\u5ff5\uff0c\u4e0d\u7ba1\u4f60\u662f\u8ba1\u7b97\u673a\u76f8\u5173\u4e13\u4e1a\u8fd8\u662f\u81ea\u5b66Java\uff0c\u4e00\u5b9a\u542c\u8fc7\u8fd9\u4e48\u4e00\u53e5\u8bdd\uff1a<\/p>\n\n\n\n<p><strong>\u65b9\u6cd5\u8c03\u7528\u53c2\u6570\u5982\u679c\u662f\u5bf9\u8c61\uff0c\u90a3\u5c31\u662f\u5f15\u7528\u4f20\u9012\uff0c\u5982\u679c\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u5c31\u662f\u503c\u4f20\u9012\u3002<\/strong><\/p>\n\n\n\n<p>\u6bd4\u5982\uff1afunction(Object o)\u5c31\u662f\u5f15\u7528\u4f20\u9012\uff0cfunction(int i)\u5c31\u662f\u503c\u4f20\u9012\u3002\u8fd9\u4e24\u4e2a\u6982\u5ff5\u4f3c\u4e4e\u5f88\u597d\u7406\u89e3\uff0c\u6211\u4eec\u53ea\u9700\u8981\u8bb0\u4f4f\u5bf9\u8c61\u548c\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u533a\u522b\u5c31\u884c\u4e86\u3002\u4f46\u662f\uff0c\u771f\u7684\u662f\u8fd9\u6837\u5417\uff1f<\/p>\n\n\n\n<p>\u6709\u4e00\u6bb5\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public static void main(String[] args) {\n        int i = 0;\n        System.out.println(i);\n        change(i);\n        System.out.println(i);\n    }\n\n    private static void change(int i) {\n        i = 1;\n    }<\/pre>\n\n\n\n<p>\u8f93\u51fa\u7ed3\u679c\u6bd4\u8f83\u597d\u731c\u6d4b\uff0c\u4e5f\u5e94\u8be5\u90fd\u80fd\u7b54\u5bf9\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">0\n0<\/pre>\n\n\n\n<p>\u4e0b\u4e00\u4e2a\u95ee\u9898\uff0c\u5982\u679c\u5c06int\u6539\u6210String\u5462\uff1f<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public static void main(String[] args) {\n        String s = \"0\";\n        System.out.println(s);\n        change(s);\n        System.out.println(s);\n    }\n\n    private static void change(String s) {\n        s = \"1\";\n    }<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">0\n0<\/pre>\n\n\n\n<p>\u55ef\uff1f\u6709\u7591\u95ee\u4e86\u5427\uff1f\u4e0d\u662f\u5f15\u7528\u4f20\u9012\u5417\uff1f\u6211\u5728\u65b9\u6cd5\u91cc\u547d\u540d\u4fee\u6539\u4e86s\u7684\u503c\uff0c\u4e3a\u4ec0\u4e48\u8f93\u51fa\u8fd8\u662f\u201d0\u201c\u5462\uff1f\u96be\u5ea6String\u4f5c\u4e3aObject\u6709\u4ec0\u4e48\u7279\u6b8a\u6027\uff1f<\/p>\n\n\n\n<p>\u522b\u6025\uff0c\u7ee7\u7eed\u770b\u4e0b\u4e00\u6bb5\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public static void main(String[] args) {\n        Person p = new Person(\"0\");\n        System.out.println(p);\n        change(p);\n        System.out.println(p);\n    }\n\n    private static void change(Person p) {\n        p = new Person(\"1\");\n    }\n\n    static class Person{\n        String name;\n\n        public Person(String name) {\n            this.name = name;\n        }\n\n        @Override\n        public String toString() {\n            return \"Person{\" +\n                    \"name='\" + name + '\\'' +\n                    '}';\n        }\n    }<\/pre>\n\n\n\n<p>\u7ed3\u679c\u4f1a\u8f93\u51fa\u4ec0\u4e48\uff1f<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Person{name='0'}\nPerson{name='0'}<\/pre>\n\n\n\n<p>\u770b\u6765String\u548c\u5176\u4ed6Object\u6ca1\u4ec0\u4e48\u4e0d\u540c\uff0c\u53ef\u662f\u8fd9\u6837\u7684\u7ed3\u679c\u597d\u50cf\u4e0d\u592a\u7b26\u5408\u6211\u4eec\u5bf9\u5f15\u7528\u4f20\u9012\u7684\u8ba4\u77e5\u554a\u3002\u5176\u5b9e\u6211\u611f\u89c9\u8fd9\u4e24\u4e2a\u6982\u5ff5\u6ca1\u6709\u5fc5\u8981\u533a\u5206\uff0c\u5b9e\u8d28\u662f\u4e00\u56de\u4e8b\uff0c\u90fd\u662f\u5c06\u6808\u4e2d\u5f15\u7528\u590d\u5236\u4e86\u4e00\u4efd\u4f20\u9012\u5230\u65b9\u6cd5\u4e2d\uff0c\u65e0\u8bba\u5728\u65b9\u6cd5\u4e2d\u5982\u4f55\u5bf9\u5f15\u7528\u64cd\u4f5c\uff0c\u90fd\u662f\u64cd\u4f5c\u7684\u526f\u672c\uff0c\u53ea\u662f\u5bf9\u4e8e\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u8bf4\uff0c\u503c\u5b58\u50a8\u5728\u6808\u4e2d\uff0c\u5f15\u7528\u5b58\u50a8\u7684\u5c31\u662f\u503c\uff0c\u800c\u5bf9\u8c61\u6765\u8bf4\uff0c\u5f15\u7528\u4e2d\u5b58\u50a8\u7684\u662f\u5bf9\u8c61\u5728\u5806\u4e2d\u7684\u5185\u5b58\u5730\u5740\uff0c\u53c2\u6570\u4f20\u9012\u65f6\u751f\u6210\u7684\u526f\u672c\u4ecd\u7136\u6307\u5411\u4e86\u539f\u6765\u5f15\u7528\u6307\u5411\u7684\u5bf9\u8c61\uff0c\u6240\u4ee5\u5982\u679c\u76f4\u63a5\u64cd\u4f5c\u8be5\u5bf9\u8c61\u662f\u6709\u6548\u7684\u3002\u7b80\u5355\u753b\u4e2a\u56fe\u65b9\u4fbf\u7406\u89e3\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/image-48-1024x390.png\" alt=\"\" class=\"wp-image-13093\" width=\"-297\" height=\"-113\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/image-48-1024x390.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/image-48-300x114.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/image-48-768x293.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/image-48-830x317.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/image-48-230x88.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/image-48-350x133.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/image-48-480x183.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/image-48.png 1458w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>\u00a0\u5982\u679c\u5bf9p\u7684\u64cd\u4f5c\u4e0d\u662f\u5c06\u8be5\u5f15\u7528\u6307\u5411\u4e00\u4e2a\u65b0\u7684\u503c\uff0c\u800c\u662f\u5bf9p\u6307\u5411\u7684\u5bf9\u8c61\u8fdb\u884c\u64cd\u4f5c\uff0c\u5c31\u80fd\u770b\u5230\u6240\u8c13\u5f15\u7528\u4f20\u9012\u7684\u6548\u679c\u4e86\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public static void main(String[] args) {\n        Person p = new Person(\"0\");\n        System.out.println(p);\n        change(p);\n        System.out.println(p);\n    }\n\n    private static void change(Person p) {\n        p.name = \"1\";\n    }\n\n    static class Person{\n        String name;\n\n        public Person(String name) {\n            this.name = name;\n        }\n\n        @Override\n        public String toString() {\n            return \"Person{\" +\n                    \"name='\" + name + '\\'' +\n                    '}';\n        }\n    }<\/pre>\n\n\n\n<p>\u6b64\u65f6\uff0c\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Person{name='0'}\nPerson{name='1'}<\/pre>\n\n\n\n<p>\u603b\u7ed3\uff1a<\/p>\n\n\n\n<p><strong>Java\u8fdb\u884c\u65b9\u6cd5\u8c03\u7528\u65f6\u53c2\u6570\u4f20\u9012\u662f\u5c06\u6808\u4e2d\u7684\u5f15\u7528\u590d\u5236\u4e86\u4e00\u4efd\u5230\u8be5\u65b9\u6cd5\u7684\u5de5\u4f5c\u533a\uff0c\u5982\u679c\u5f15\u7528\u6307\u5411\u4e86\u4e00\u4e2a\u5806\u4e2d\u7684\u5bf9\u8c61\uff0c\u90a3\u4e48\u526f\u672c\u4e5f\u6307\u5411\u8fd9\u4e2a\u5bf9\u8c61\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u7528\u4f20\u9012\u548c\u503c\u4f20\u9012\uff0c\u4ece\u4e0a\u5b66\u90a3\u4f1a\u513f\u5c31\u5f00\u59cb\u5f3a\u8c03\u7684\u6982\u5ff5\uff0c\u4e0d\u7ba1\u4f60\u662f\u8ba1\u7b97\u673a\u76f8\u5173\u4e13\u4e1a\u8fd8\u662f\u81ea\u5b66Java\uff0c\u4e00\u5b9a\u542c\u8fc7\u8fd9\u4e48\u4e00\u53e5\u8bdd\uff1a  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/13092"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13092"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/13092\/revisions"}],"predecessor-version":[{"id":13094,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/13092\/revisions\/13094"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}