{"id":749,"date":"2022-10-07T18:29:19","date_gmt":"2022-10-07T10:29:19","guid":{"rendered":"https:\/\/qaqaq.top\/?p=749"},"modified":"2022-11-27T12:39:55","modified_gmt":"2022-11-27T04:39:55","slug":"%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%ad-equals%e7%bb%83%e4%b9%a01%ef%bc%9a%e4%bb%a3%e7%a0%81%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=749","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e2d)-equals()\u7ec3\u4e601\uff1a\u4ee3\u7801\u5b9e\u73b0"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P299;\r\n\r\npublic class OdrerTest {\r\n\r\n\tpublic static void main(String&#91;] args) {\r\n\r\n\t\tOrder order1 = new Order(1001, \"AA\");\r\n\t\tOrder order2 = new Order(1001, \"BB\");\r\n\r\n\t\tSystem.out.println(order1.equals(order2));\r\n\t\t\r\n\t\tOrder order3 = new Order(1001, \"BB\");\r\n\t\tSystem.out.println(order2.equals(order3));\r\n\t\t\r\n\/\/\t\tString s1 = \"BB\";\r\n\/\/\t\tString s2 = \"BB\";\r\n\/\/\t\tSystem.out.println(s1 == s2);\/\/true\r\n\t\t\r\n\t}\r\n}\r\n\r\nclass Order {\r\n\r\n\tprivate int orderld;\r\n\tprivate String orderName;\r\n\r\n\tpublic Order(int orderld, String orderName) {\r\n\t\tsuper();\r\n\t\tthis.orderld = orderld;\r\n\t\tthis.orderName = orderName;\r\n\t}\r\n\r\n\tpublic int getOrderld() {\r\n\t\treturn orderld;\r\n\t}\r\n\r\n\tpublic void setOrderld(int orderld) {\r\n\t\tthis.orderld = orderld;\r\n\t}\r\n\r\n\tpublic String getOrderName() {\r\n\t\treturn orderName;\r\n\t}\r\n\r\n\tpublic void setOrderName(String orderName) {\r\n\t\tthis.orderName = orderName;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic boolean equals(Object obj) {\r\n\t\tif(this == obj) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tif(obj instanceof Order) {\r\n\t\t\tOrder order = (Order)obj;\r\n\t\t\t\/\/\u6b63\u786e\u7684\uff1a\r\n\t\t\treturn this.orderld == order.orderld &amp;&amp; \r\n\t\t\t\t\tthis.orderName.equals(order.orderName);\r\n\t\t\t\/\/\u9519\u8bef\u7684\uff1a\r\n\/\/\t\t\treturn this.orderld == order.orderld &amp;&amp; \r\n\/\/\t\t\t\t\tthis.orderName == order.orderName;\r\n\t\t}\r\n\t\t\r\n\t\treturn false;\r\n\t}\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-749","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/749"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=749"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/749\/revisions"}],"predecessor-version":[{"id":750,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/749\/revisions\/750"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}