{"id":622,"date":"2023-12-25T18:01:01","date_gmt":"2023-12-25T10:01:01","guid":{"rendered":""},"modified":"2023-12-25T18:01:01","modified_gmt":"2023-12-25T10:01:01","slug":"JAVA\u91cd\u5199\u548c\u91cd\u8f7d\u7684\u533a\u522b","status":"publish","type":"post","link":"https:\/\/mushiming.com\/622.html","title":{"rendered":"JAVA\u91cd\u5199\u548c\u91cd\u8f7d\u7684\u533a\u522b"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n


\n

<\/p>\n
\n

\u6587\u7ae0\u76ee\u5f55<\/h3>\n
    \n
  • \n
      \n
    • @[toc]<\/li>\n<\/ul>\n<\/li>\n
    • \u95ee\uff1a Java \u91cd\u8f7d\u4e0e\u91cd\u5199\u662f\u4ec0\u4e48\uff1f\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/li>\n
    • \u95ee\uff1aJava \u6784\u9020\u65b9\u6cd5\u80fd\u5426\u88ab\u91cd\u5199\u548c\u91cd\u8f7d\uff1f<\/li>\n
    • \u95ee\uff1a\u4e0b\u9762\u7a0b\u5e8f\u7684\u8fd0\u884c\u7ed3\u679c\u662f\u4ec0\u4e48\uff0c\u4e3a\u4ec0\u4e48\uff1f<\/li>\n<\/ul><\/div>\n<\/h2>\n

      \u95ee\uff1a Java \u91cd\u8f7d\u4e0e\u91cd\u5199\u662f\u4ec0\u4e48\uff1f\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/h1>\n

      \u7b54\uff1a
      \u3000\u3000\u91cd\u8f7d<\/strong>\uff08Overload\uff09\u662f\u8ba9\u7c7b\u4ee5\u7edf\u4e00\u7684\u65b9\u5f0f\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u6570\u636e\u7684\u4e00\u79cd\u624b\u6bb5\uff0c\u5b9e\u8d28\u8868\u73b0\u5c31\u662f\u591a\u4e2a\u5177\u6709\u4e0d\u540c\u7684\u53c2\u6570\u4e2a\u6570\u6216\u8005\u7c7b\u578b\u7684\u540c\u540d\u51fd\u6570<\/code>\uff08\u8fd4\u56de\u503c\u7c7b\u578b\u53ef\u968f\u610f\uff0c\u4e0d\u80fd\u4ee5\u8fd4\u56de\u7c7b\u578b\u4f5c\u4e3a\u91cd\u8f7d\u51fd\u6570\u7684\u533a\u5206\u6807\u51c6\uff09\u540c\u65f6\u5b58\u5728\u4e8e\u540c\u4e00\u4e2a\u7c7b\u4e2d\uff0c\u662f\u4e00\u4e2a\u7c7b\u4e2d\u591a\u6001\u6027\u7684\u4e00\u79cd\u8868\u73b0\uff08\u8c03\u7528\u65b9\u6cd5\u65f6\u901a\u8fc7\u4f20\u9012\u4e0d\u540c\u53c2\u6570\u4e2a\u6570\u548c\u53c2\u6570\u7c7b\u578b<\/code>\u6765\u51b3\u5b9a\u5177\u4f53\u4f7f\u7528\u54ea\u4e2a\u65b9\u6cd5\u7684\u591a\u6001\u6027\uff09\u3002<\/p>\n


      \n \"JAVA\u91cd\u5199\u548c\u91cd\u8f7d\u7684\u533a\u522b \u56fe1. Android\u7c7b\u4e2d\u7684\u4e00\u4e2a\u91cd\u8f7d\u4f8b\u5b50
      \n<\/center> <\/p>\n

      \u91cd\u5199<\/strong>\uff08Override\uff09\u662f\u7236\u7c7b\u4e0e\u5b50\u7c7b\u4e4b\u95f4\u7684\u591a\u6001\u6027\uff0c\u5b9e\u8d28\u662f\u5bf9\u7236\u7c7b\u7684\u51fd\u6570\u8fdb\u884c\u91cd\u65b0\u5b9a\u4e49\uff0c\u5982\u679c\u5728\u5b50\u7c7b\u4e2d\u5b9a\u4e49\u67d0\u65b9\u6cd5\u4e0e\u5176\u7236\u7c7b\u6709\u76f8\u540c\u7684\u540d\u79f0\u548c\u53c2\u6570\u5219\u8be5\u65b9\u6cd5\u88ab\u91cd\u5199\uff0c\u4e0d\u8fc7\u5b50\u7c7b\u51fd\u6570\u7684\u8bbf\u95ee\u4fee\u9970\u6743\u9650\u4e0d\u80fd\u5c0f\u4e8e\u7236\u7c7b\u7684\uff1b\u82e5\u5b50\u7c7b\u4e2d\u7684\u65b9\u6cd5\u4e0e\u7236\u7c7b\u4e2d\u7684\u67d0\u4e00\u65b9\u6cd5\u5177\u6709\u76f8\u540c\u7684\u65b9\u6cd5\u540d\u3001\u8fd4\u56de\u7c7b\u578b\u548c\u53c2\u6570\u8868\uff0c\u5219\u65b0\u65b9\u6cd5\u5c06\u8986\u76d6\u539f\u6709\u7684\u65b9\u6cd5\uff0c\u5982\u9700\u7236\u7c7b\u4e2d\u539f\u6709\u7684\u65b9\u6cd5\u5219\u53ef\u4f7f\u7528 super \u5173\u952e\u5b57\u3002<\/p>\n


      \n \"JAVA\u91cd\u5199\u548c\u91cd\u8f7d\u7684\u533a\u522b \u56fe2. Android\u7c7b\u4e2d\u7684\u5e38\u89c1\u7684\u4e00\u4e2a\u91cd\u5199\u4f8b\u5b50
      \n<\/center> ---------- <\/p>\n

      **\u91cd\u8f7d\u89c4\u5219\uff1a**\u5fc5\u987b\u5177\u6709\u4e0d\u540c\u7684\u53c2\u6570\u5217\u8868\uff1b \u53ef\u4ee5\u6709\u4e0d\u540c\u7684\u8fd4\u56de\u7c7b\u578b\uff1b\u53ef\u4ee5\u6709\u4e0d\u540c\u7684\u8bbf\u95ee\u4fee\u9970\u7b26\uff1b\u53ef\u4ee5\u629b\u51fa\u4e0d\u540c\u7684\u5f02\u5e38\u3002<\/p>\n

      \u91cd\u5199\u89c4\u5219\uff1a<\/strong>\u53c2\u6570\u5217\u8868\u5fc5\u987b\u5b8c\u5168\u4e0e\u88ab\u91cd\u5199\u7684\u65b9\u6cd5\u76f8\u540c\uff0c\u5426\u5219\u4e0d\u80fd\u79f0\u5176\u4e3a\u91cd\u5199\uff1b\u8fd4\u56de\u7c7b\u578b\u5fc5\u987b\u4e00\u76f4\u4e0e\u88ab\u91cd\u5199\u7684\u65b9\u6cd5\u76f8\u540c\uff0c\u5426\u5219\u4e0d\u80fd\u79f0\u5176\u4e3a\u91cd\u5199\uff1b<\/code>\u8bbf\u95ee\u4fee\u9970\u7b26\u7684\u9650\u5236\u4e00\u5b9a\u8981\u5927\u4e8e\u7b49\u4e8e\u88ab\u91cd\u5199\u65b9\u6cd5\u7684\u8bbf\u95ee\u4fee\u9970\u7b26\uff1b\u91cd\u5199\u65b9\u6cd5\u4e00\u5b9a\u4e0d\u80fd\u629b\u51fa\u65b0\u7684\u68c0\u67e5\u5f02\u5e38\u6216\u8005\u6bd4\u88ab\u91cd\u5199\u65b9\u6cd5\u7533\u660e\u66f4\u52a0\u5bbd\u6cdb\u7684\u68c0\u67e5\u578b\u5f02\u5e38\uff0c\u8b6c\u5982\u7236\u7c7b\u65b9\u6cd5\u58f0\u660e\u4e86\u4e00\u4e2a\u68c0\u67e5\u5f02\u5e38 IOException\uff0c\u5728\u91cd\u5199\u8fd9\u4e2a\u65b9\u6cd5\u65f6\u5c31\u4e0d\u80fd\u629b\u51fa Exception\uff0c\u53ea\u80fd\u629b\u51fa IOException \u7684\u5b50\u7c7b\u5f02\u5e38\uff0c\u53ef\u4ee5\u629b\u51fa\u975e\u68c0\u67e5\u5f02\u5e38\u3002<\/p>\n

      \u91cd\u8f7d\u4e0e\u91cd\u5199\u662f Java \u591a\u6001\u6027<\/code>\u7684\u4e0d\u540c\u8868\u73b0\u3002<\/strong><\/em>
      \u3000\u3000\u91cd\u5199\u662f\u7236\u7c7b\u4e0e\u5b50\u7c7b\u4e4b\u95f4\u591a\u6001\u6027\u7684\u8868\u73b0\uff0c\u5728\u8fd0\u884c\u65f6\u8d77\u4f5c\u7528\uff08\u52a8\u6001\u591a\u6001\u6027\uff0c\u8b6c\u5982\u5b9e\u73b0\u52a8\u6001\u7ed1\u5b9a\uff09<\/strong><\/em>
      \u3000\u3000\u800c\u91cd\u8f7d\u662f\u4e00\u4e2a\u7c7b\u4e2d\u591a\u6001\u6027\u7684\u8868\u73b0\uff0c\u5728\u7f16\u8bd1\u65f6\u8d77\u4f5c\u7528\uff08\u9759\u6001\u591a\u6001\u6027\uff0c\u8b6c\u5982\u5b9e\u73b0\u9759\u6001\u7ed1\u5b9a\uff09\u3002<\/strong><\/em><\/p>\n


      \n

      \u95ee\uff1aJava \u6784\u9020\u65b9\u6cd5\u80fd\u5426\u88ab\u91cd\u5199\u548c\u91cd\u8f7d\uff1f<\/h1>\n

      \u7b54\uff1a
      \u3000\u3000\u91cd\u5199\u662f\u5b50\u7c7b\u65b9\u6cd5\u91cd\u5199\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u91cd\u5199\u7684\u65b9\u6cd5\u540d\u4e0d\u53d8\uff0c\u800c\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u540d\u5fc5\u987b\u4e0e\u7c7b\u540d\u4e00\u81f4\uff0c\u5047\u8bbe\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u5982\u679c\u80fd\u591f\u88ab\u5b50\u7c7b\u91cd\u5199\u5219\u5b50\u7c7b\u7c7b\u540d\u5fc5\u987b\u4e0e\u7236\u7c7b\u7c7b\u540d\u4e00\u81f4\u624d\u884c\uff0c\u6240\u4ee5 Java \u7684\u6784\u9020\u65b9\u6cd5<\/strong>\u662f\u4e0d\u80fd\u88ab\u91cd\u5199<\/code>\u7684\u3002\u800c\u91cd\u8f7d\u662f\u9488\u5bf9\u540c\u4e00\u4e2a\u7684\uff0c\u6240\u4ee5\u6784\u9020\u65b9\u6cd5\u53ef\u4ee5\u88ab\u91cd\u8f7d<\/code>\u3002<\/p>\n

      \u95ee\uff1a\u4e0b\u9762\u7a0b\u5e8f\u7684\u8fd0\u884c\u7ed3\u679c\u662f\u4ec0\u4e48\uff0c\u4e3a\u4ec0\u4e48\uff1f<\/h1>\n
      public<\/span> class<\/span> Demo<\/span> { \n   <\/span>\n    \npublic<\/span> boolean<\/span> equals<\/span>(<\/span> Demo other)<\/span> { \n   <\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"use Demo equals.\"<\/span> )<\/span>;<\/span>\n        return<\/span> true<\/span>;<\/span>    \n}<\/span>\n    \npublic<\/span> static<\/span> void<\/span> main<\/span>(<\/span>String[<\/span>]<\/span> args)<\/span> { \n   <\/span>    \n    Object o1 =<\/span>new<\/span> Demo<\/span> (<\/span>)<\/span>;<\/span>\n    Object o2 =<\/span>new<\/span> Demo<\/span> (<\/span>)<\/span>;<\/span>        \n    Demo o3 =<\/span>new<\/span> Demo<\/span> (<\/span>)<\/span>;<\/span>\n    Demo o4 =<\/span>new<\/span> Demo<\/span> (<\/span>)<\/span>;<\/span>\n\n   if<\/span> (<\/span>o1.<\/span>equals<\/span>(<\/span>o2)<\/span>)<\/span> { \n   <\/span>\n            System.<\/span>out.<\/span>println<\/span>(<\/span>\"o1 is equal with o2.\"<\/span>)<\/span>;<\/span>\n        }<\/span>\n\n   if<\/span>(<\/span>o3.<\/span>equals<\/span>(<\/span>o4)<\/span>)<\/span> { \n   <\/span>             \n            System.<\/span>out.<\/span>println<\/span>(<\/span>\"o3 is equal with o4.\"<\/span>)<\/span>;<\/span>\n        }<\/span>\n    }<\/span>\n}<\/span>\n<\/code><\/pre>\n

      \u7b54\uff1a\u4e0a\u9762\u7a0b\u5e8f\u7684\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\u3002<\/p>\n

      use Demo equals.\no3 is equal with o4.\n<\/code><\/pre>\n

      \u56e0\u4e3a Demo \u7c7b\u4e2d\u7684 public boolean equals(Demo other) \u65b9\u6cd5\u5e76\u6ca1\u6709\u91cd\u5199 Object \u7c7b\u4e2d\u7684 public boolean equals(Object obj) \u65b9\u6cd5\uff0c\u539f\u56e0\u662f\u5176\u8fdd\u80cc\u4e86\u53c2\u6570\u89c4\u5219\uff0c\u5176\u4e2d\u4e00\u4e2a\u662f Demo \u7c7b\u578b\u800c\u53e6\u4e00\u4e2a\u662f Object \u7c7b\u578b\uff0c\u56e0\u6b64\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u662f\u91cd\u8f7d\u5173\u7cfb\uff08\u53d1\u751f\u5728\u7f16\u8bd1\u65f6\uff09\u800c\u4e0d\u662f\u91cd\u5199\u5173\u7cfb\uff1b\u6545\u5f53\u8c03\u7528 o1.equals(o2) \u65f6\uff0co2 \u662f Object \u7c7b\u578b\u53c2\u6570\uff0c\u5b9e\u9645\u4e0a\u8c03\u7528\u4e86 Object \u7c7b\u4e2d\u7684 public boolean equals(Object obj) \u65b9\u6cd5<\/code>\uff0c\u56e0\u4e3a\u5728\u7f16\u8bd1\u65f6 o1 \u548c o2 \u90fd\u662f Object \u7c7b\u578b\uff0c\u800cObject \u7c7b\u7684 equals \u65b9\u6cd5<\/strong>\u662f\u901a\u8fc7\u6bd4\u8f83\u5185\u5b58\u5730\u5740\u624d\u8fd4\u56de false\uff1b\u5f53\u8c03\u7528 o3.equals(o4) \u65f6\uff0c\u5b9e\u9645\u4e0a\u8c03\u7528\u4e86 Demo \u7c7b\u4e2d\u7684 equals(Demo other) \u65b9\u6cd5\uff0c\u56e0\u4e3a\u5728\u7f16\u8bd1\u65f6 o3 \u548c o4 \u90fd\u662f Demo \u7c7b\u578b\u7684\uff0c\u6240\u4ee5\u624d\u6709\u4e0a\u9762\u7684\u6253\u5370\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"JAVA\u91cd\u5199\u548c\u91cd\u8f7d\u7684\u533a\u522b\u95ee\uff1aJava\u91cd\u8f7d\u4e0e\u91cd\u5199\u662f\u4ec0\u4e48\uff1f\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u7b54\uff1a\u3000\u3000\u91cd\u8f7d\uff08Overload\uff09\u662f\u8ba9\u7c7b\u4ee5\u7edf\u4e00\u7684\u65b9\u5f0f\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u6570\u636e...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/622"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=622"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/622\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}