{"id":246,"date":"2019-01-24T17:55:04","date_gmt":"2019-01-24T09:55:04","guid":{"rendered":"https:\/\/qtvz.com\/?p=246"},"modified":"2019-04-26T13:02:11","modified_gmt":"2019-04-26T05:02:11","slug":"jdk1-8-0_161_64%e6%ba%90%e7%a0%81%e8%a7%a3%e6%9e%90%e7%b3%bb%e5%88%97%e4%b9%8bjava-lang-object","status":"publish","type":"post","link":"https:\/\/qtvz.com\/246.html","title":{"rendered":"JDK1.8.0_161_64\u6e90\u7801\u89e3\u6790\u7cfb\u5217\u4e4bjava.lang.Object"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression-->\n<div class=\"wp-block-file\"><a href=\"https:\/\/qtvz.com\/wp-content\/uploads\/2019\/01\/9a809661437d19f7.zip\">JAVA_JDK1.8.0_161_64\u6e90\u7801<\/a><a href=\"https:\/\/qtvz.com\/wp-content\/uploads\/2019\/01\/9a809661437d19f7.zip\" class=\"wp-block-file__button\" download>\u4e0b\u8f7d<\/a><\/div>\n\n\n\n<p class=\"has-background has-medium-font-size has-vivid-cyan-blue-background-color\">1\u3001\u7c7b\u6784\u9020\u5668public Object();<\/p>\n\n\n\n<p><strong>\u5927\u90e8\u5206\u60c5\u51b5\u4e0b<\/strong>\uff0cJava\u4e2d\u901a\u8fc7\u5f62\u5982 new A(args..)\u5f62\u5f0f\u521b\u5efa\u4e00\u4e2a\u5c5e\u4e8e\u8be5\u7c7b\u578b\u7684\u5bf9\u8c61\u3002\u5176\u4e2dA\u5373\u662f\u7c7b\u540d\uff0cA(args..)\u5373\u6b64\u7c7b\u5b9a\u4e49\u4e2d\u76f8\u5bf9\u5e94\u7684\u6784\u9020\u51fd\u6570\u3002\u901a\u8fc7\u6b64\u79cd\u5f62\u5f0f\u521b\u5efa\u7684\u5bf9\u8c61\u90fd\u662f\u901a\u8fc7\u7c7b\u4e2d\u7684\u6784\u9020\u51fd\u6570\u5b8c\u6210\u3002\u4e3a\u4f53\u73b0\u6b64\u7279\u6027\uff0cJava\u4e2d\u89c4\u5b9a\uff1a\u5728\u7c7b\u5b9a\u4e49\u8fc7\u7a0b\u4e2d\uff0c\u5bf9\u4e8e\u672a\u5b9a\u4e49\u6784\u9020\u51fd\u6570\u7684\u7c7b\uff0c\u9ed8\u8ba4\u4f1a\u6709\u4e00\u4e2a\u65e0\u53c2\u6570\u7684\u6784\u9020\u51fd\u6570\uff0c\u4f5c\u4e3a\u6240\u6709\u7c7b\u7684\u57fa\u7c7b\uff0cObject\u7c7b\u81ea\u7136\u8981\u53cd\u6620\u51fa\u6b64\u7279\u6027\uff0c\u5728\u6e90\u7801\u4e2d\uff0c\u672a\u7ed9\u51faObject\u7c7b\u6784\u9020\u51fd\u6570\u5b9a\u4e49\uff0c\u4f46\u5b9e\u9645\u4e0a\uff0c\u6b64\u6784\u9020\u51fd\u6570\u662f\u5b58\u5728\u7684\u3002 <\/p>\n\n\n\n<p> \u5f53\u7136\uff0c\u5e76\u4e0d\u662f\u6240\u6709\u7684\u7c7b\u90fd\u662f\u901a\u8fc7\u6b64\u79cd\u65b9\u5f0f\u53bb\u6784\u5efa\uff0c\u4e5f\u81ea\u7136\u7684\uff0c<strong>\u5e76\u4e0d\u662f\u6240\u6709\u7684\u7c7b\u6784\u9020\u51fd\u6570\u90fd\u662fpublic\u3002<\/strong><\/p>\n\n\n\n<p class=\"has-background has-medium-font-size has-vivid-cyan-blue-background-color\"> 2\u3001private static native void registerNatives(); <\/p>\n\n\n\n<p> Java\u4e2d\uff0c\u7528native\u5173\u952e\u5b57\u4fee\u9970\u7684\u51fd\u6570\u8868\u660e\u8be5\u65b9\u6cd5\u7684\u5b9e\u73b0\u5e76\u4e0d\u662f\u5728Java\u4e2d\u53bb\u5b8c\u6210\uff0c\u800c\u662f\u7531C++\u53bb\u5b8c\u6210\uff0c\u5e76\u88ab\u7f16\u8bd1\u6210\u4e86.dll\uff0c\u7531Java\u53bb\u8c03\u7528\u3002\u65b9\u6cd5\u7684\u5177\u4f53\u5b9e\u73b0\u4f53\u5728dll\u6587\u4ef6\u4e2d\uff0c\u5bf9\u4e8e\u50cfWindow\uff0cLinux\uff0cMac\u4e0d\u540c\u5e73\u53f0\uff0c\u5176\u5177\u4f53\u5b9e\u73b0\u6709\u6240\u4e0d\u540c\uff0c\u4e3b\u8981\u4f5c\u7528\u662f\u5c06C++\u7684\u65b9\u6cd5\u6620\u5c04\u5230Java\u4e2d\uff0c\u5b9e\u73b0\u65b9\u6cd5\u547d\u540d\u7684\u89e3\u85d5\u3002<\/p>\n\n\n\n<p> \u65e2\u7136\u5982\u6b64\uff0c\u53ef\u80fd\u6709\u4eba\u4f1a\u95ee\uff0cregisterNatives()\u4fee\u9970\u7b26\u4e3aprivate\uff0c\u4e14\u5e76\u6ca1\u6709\u6267\u884c\uff0c\u4f5c\u7528\u4f55\u4ee5\u8fbe\u5230\uff1f\u5176\u5b9e\uff0c\u5728Java\u6e90\u7801\u4e2d\uff0c\u6b64\u65b9\u6cd5\u7684\u58f0\u660e\u540e\u6709\u7d27\u63a5\u7740\u4e00\u6bb5\u9759\u6001\u4ee3\u7801\u5757\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    private static native void registerNatives();\n    static {\n        registerNatives();\n    }<\/code><\/pre>\n\n\n\n<p class=\"has-background has-medium-font-size has-vivid-cyan-blue-background-color\">3\u3001public final native Class getClass();<\/p>\n\n\n\n<p><strong>getClass()\u4e5f\u662f\u4e00\u4e2anative\u65b9\u6cd5\uff0c\u8fd4\u56de\u7684\u662f\u6b64Object\u5bf9\u8c61\u7684\u7c7b\u5bf9\u8c61\/\u8fd0\u884c\u65f6\u7c7b\u5bf9\u8c61Class&lt;?&gt;\u3002\u6548\u679c\u4e0eObject.class\u76f8\u540c\u3002<\/strong><\/p>\n\n\n\n<p>\u9996\u5148\u89e3\u91ca\u4e0b\"\u7c7b\u5bf9\u8c61\"\u7684\u6982\u5ff5\uff1a\u5728Java\u4e2d\uff0c\u7c7b\u662f\u662f\u5bf9\u5177\u6709\u4e00\u7ec4\u76f8\u540c\u7279\u5f81\u6216\u884c\u4e3a\u7684\u5b9e\u4f8b\u7684\u62bd\u8c61\u5e76\u8fdb\u884c\u63cf\u8ff0\uff0c\u5bf9\u8c61\u5219\u662f\u6b64\u7c7b\u6240\u63cf\u8ff0\u7684\u7279\u5f81\u6216\u884c\u4e3a\u7684\u5177\u4f53\u5b9e\u4f8b\u3002\u4f5c\u4e3a\u6982\u5ff5\u5c42\u6b21\u7684\u7c7b\uff0c\u5176\u672c\u8eab\u4e5f\u5177\u6709\u67d0\u4e9b\u5171\u540c\u7684\u7279\u6027\uff0c\u5982\u90fd\u5177\u6709\u7c7b\u540d\u79f0\u3001\u7531\u7c7b\u52a0\u8f7d\u5668\u53bb\u52a0\u8f7d\uff0c\u90fd\u5177\u6709\u5305\uff0c\u5177\u6709\u7236\u7c7b\uff0c\u5c5e\u6027\u548c\u65b9\u6cd5\u7b49\u3002\u4e8e\u662f\uff0cJava\u4e2d\u6709\u4e13\u95e8\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7c7b\uff0cClass\uff0c\u53bb\u63cf\u8ff0\u5176\u4ed6\u7c7b\u6240\u5177\u6709\u7684\u8fd9\u4e9b\u7279\u6027\uff0c\u56e0\u6b64\uff0c\u4ece\u6b64\u89d2\u5ea6\u53bb\u770b\uff0c\u7c7b\u672c\u8eab\u4e5f\u90fd\u662f\u5c5e\u4e8eClass\u7c7b\u7684\u5bf9\u8c61\u3002\u4e3a\u4e0e\u7ecf\u5e38\u610f\u4e49\u4e0a\u7684\u5bf9\u8c61\u76f8\u533a\u5206\uff0c\u5728\u6b64\u79f0\u4e4b\u4e3a\"\u7c7b\u5bf9\u8c61\"\u3002<\/p>\n\n\n\n<p class=\"has-background has-medium-font-size has-vivid-cyan-blue-background-color\">4\u3001public native int hashCode();<\/p>\n\n\n\n<p> hashCode()\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u6574\u5f62\u6570\u503c\uff0c\u8868\u793a\u8be5\u5bf9\u8c61\u7684\u54c8\u5e0c\u7801\u503c\u3002 <\/p>\n\n\n\n<p>hashCode()\u5177\u6709\u5982\u4e0b\u7ea6\u5b9a\uff1a<\/p>\n\n\n\n<p>1).\u5728Java\u5e94\u7528\u7a0b\u5e8f\u7a0b\u5e8f\u6267\u884c\u671f\u95f4\uff0c\u5bf9\u4e8e\u540c\u4e00\u5bf9\u8c61\u591a\u6b21\u8c03\u7528hashCode()\u65b9\u6cd5\u65f6\uff0c\u5176\u8fd4\u56de\u7684\u54c8\u5e0c\u7801\u662f\u76f8\u540c\u7684\uff0c\u524d\u63d0\u662f\u5c06\u5bf9\u8c61\u8fdb\u884cequals\u6bd4\u8f83\u65f6\u6240\u7528\u7684\u6807\u5c3a\u4fe1\u606f\u672a\u505a\u4fee\u6539\u3002\u5728Java\u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u6b21\u6267\u884c\u5230\u53e6\u5916\u4e00\u6b21\u6267\u884c\uff0c\u540c\u4e00\u5bf9\u8c61\u7684hashCode()\u8fd4\u56de\u7684\u54c8\u5e0c\u7801\u65e0\u987b\u4fdd\u6301\u4e00\u81f4\uff1b<\/p>\n\n\n\n<p>2).\u5982\u679c\u4e24\u4e2a\u5bf9\u8c61\u76f8\u7b49\uff08\u4f9d\u636e\uff1a\u8c03\u7528equals()\u65b9\u6cd5\uff09\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u5bf9\u8c61\u8c03\u7528hashCode()\u8fd4\u56de\u7684\u54c8\u5e0c\u7801\u4e5f\u5fc5\u987b\u76f8\u7b49\uff1b<\/p>\n\n\n\n<p>3).\u53cd\u4e4b\uff0c\u4e24\u4e2a\u5bf9\u8c61\u8c03\u7528hasCode()\u8fd4\u56de\u7684\u54c8\u5e0c\u7801\u76f8\u7b49\uff0c\u8fd9\u4e24\u4e2a\u5bf9\u8c61\u4e0d\u4e00\u5b9a\u76f8\u7b49\u3002<\/p>\n\n\n\n<p><strong>\u5373\u4e25\u683c\u7684\u6570\u5b66\u903b\u8f91\u8868\u793a\u4e3a\uff1a \u4e24\u4e2a\u5bf9\u8c61\u76f8\u7b49 &lt;=&gt; &nbsp;equals()\u76f8\u7b49 &nbsp;=&gt; hashCode()\u76f8\u7b49\u3002\u56e0\u6b64\uff0c\u91cd\u5199equlas()\u65b9\u6cd5\u5fc5\u987b\u91cd\u5199hashCode()\u65b9\u6cd5\uff0c\u4ee5\u4fdd\u8bc1\u6b64\u903b\u8f91\u4e25\u683c\u6210\u7acb\uff0c\u540c\u65f6\u53ef\u4ee5\u63a8\u7406\u51fa\uff1ahasCode()\u4e0d\u76f8\u7b49 =&gt; equals\uff08\uff09\u4e0d\u76f8\u7b49 &lt;=&gt; \u4e24\u4e2a\u5bf9\u8c61\u4e0d\u76f8\u7b49\u3002<\/strong><\/p>\n\n\n\n<p>\u53ef\u80fd\u6709\u4eba\u5728\u6b64\u4ea7\u751f\u7591\u95ee\uff1a\u65e2\u7136<strong>\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u76f8\u7b49\u7684\u552f\u4e00\u6761\u4ef6\uff08\u4e5f\u662f\u51b2\u8981\u6761\u4ef6\uff09\u662fequals<\/strong>\uff0c\u90a3\u4e48\u4e3a\u4ec0\u4e48\u8fd8\u8981\u5f04\u51fa\u4e00\u4e2ahashCode()\uff0c\u5e76\u4e14\u8fdb\u884c\u5982\u6b64\u7ea6\u5b9a\uff0c\u5f04\u5f97\u8fd9\u4e48\u9ebb\u70e6\uff1f<\/p>\n\n\n\n<p>\u5176\u5b9e\uff0c\u8fd9\u4e3b\u8981\u4f53\u73b0\u5728hashCode()\u65b9\u6cd5\u7684\u4f5c\u7528\u4e0a\uff0c\u5176\u4e3b\u8981\u7528\u4e8e\u589e\u5f3a\u54c8\u5e0c\u8868\u7684\u6027\u80fd\u3002<\/p>\n\n\n\n<p>\u4ee5\u96c6\u5408\u7c7b\u4e2d\uff0c\u4ee5Set\u4e3a\u4f8b\uff0c\u5f53\u65b0\u52a0\u4e00\u4e2a\u5bf9\u8c61\u65f6\uff0c\u9700\u8981\u5224\u65ad\u73b0\u6709\u96c6\u5408\u4e2d\u662f\u5426\u5df2\u7ecf\u5b58\u5728\u4e0e\u6b64\u5bf9\u8c61\u76f8\u7b49\u7684\u5bf9\u8c61\uff0c\u5982\u679c\u6ca1\u6709hashCode()\u65b9\u6cd5\uff0c\u9700\u8981\u5c06Set\u8fdb\u884c\u4e00\u6b21\u904d\u5386\uff0c\u5e76\u9010\u4e00\u7528equals()\u65b9\u6cd5\u5224\u65ad\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u76f8\u7b49\uff0c\u6b64\u79cd\u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u4e3ao(n)\u3002\u901a\u8fc7\u501f\u52a9\u4e8ehasCode\u65b9\u6cd5\uff0c\u5148\u8ba1\u7b97\u51fa\u5373\u5c06\u65b0\u52a0\u5165\u5bf9\u8c61\u7684\u54c8\u5e0c\u7801\uff0c\u7136\u540e\u6839\u636e\u54c8\u5e0c\u7b97\u6cd5\u8ba1\u7b97\u51fa\u6b64\u5bf9\u8c61\u7684\u4f4d\u7f6e\uff0c\u76f4\u63a5\u5224\u65ad\u6b64\u4f4d\u7f6e\u4e0a\u662f\u5426\u5df2\u6709\u5bf9\u8c61\u5373\u53ef\u3002\uff08\u6ce8\uff1aSet\u7684\u5e95\u5c42\u7528\u7684\u662fMap\u7684\u539f\u7406\u5b9e\u73b0\uff09<\/p>\n\n\n\n<p><strong>\u5728\u6b64\u9700\u8981\u7ea0\u6b63\u4e00\u4e2a\u7406\u89e3\u4e0a\u7684\u8bef\u533a\uff1a\u5bf9\u8c61\u7684hashCode()\u8fd4\u56de\u7684\u4e0d\u662f\u5bf9\u8c61\u6240\u5728\u7684\u7269\u7406\u5185\u5b58\u5730\u5740\u3002\u751a\u81f3\u4e5f\u4e0d\u4e00\u5b9a\u662f\u5bf9\u8c61\u7684\u903b\u8f91\u5730\u5740\uff0chashCode()\u76f8\u540c\u7684\u4e24\u4e2a\u5bf9\u8c61\uff0c\u4e0d\u4e00\u5b9a\u76f8\u7b49\uff0c\u6362\u8a00\u4e4b\uff0c\u4e0d\u76f8\u7b49\u7684\u4e24\u4e2a\u5bf9\u8c61\uff0chashCode()\u8fd4\u56de\u7684\u54c8\u5e0c\u7801\u53ef\u80fd\u76f8\u540c\u3002<\/strong><\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u91cd\u5199\u4e86equals()\u65b9\u6cd5\u540e\uff0c\u9700\u8981\u91cd\u5199hashCode()\u65b9\u6cd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.corn.objectsummary;\n\npublic class User {\n\n    private int uid;\n    private String name;\n    private int age;\n\n    public int getUid() {\n        return uid;\n    }\n\n    public void setUid(int uid) {\n        this.uid = uid;\n    }\n\n    protected String getName() {\n        return name;\n    }\n\n    public void setName(String name) {\n        this.name = name;\n    }\n\n    public int getAge() {\n        return age;\n    }\n\n    public void setAge(int age) {\n        this.age = age;\n    }\n\n    @Override\n    public boolean equals(Object obj) {\n        if (obj == null || !(obj instanceof User)) {\n            return false;\n        }\n        if (((User) obj).getUid() == this.getUid()) {\n            return true;\n        }\n        return false;\n    }\n\n    @Override\n    public int hashCode() {\n        int result = 17;\n        result = 31 * result + this.getUid();\n        return result;\n    }\n}<\/code><\/pre>\n\n\n\n<p> \u6ce8\uff1a\u4e0a\u8ff0hashCode()\u7684\u91cd\u5199\u4e2d\u51fa\u73b0\u4e86result*31\uff0c\u662f\u56e0\u4e3aresult*31 = (result&lt;&lt;5) - result\u3002\u4e4b\u6240\u4ee5\u9009\u62e931\uff0c\u662f\u56e0\u4e3a\u5de6\u79fb\u8fd0\u7b97\u548c\u51cf\u8fd0\u7b97\u8ba1\u7b97\u6548\u7387\u8fdc\u5927\u4e8e\u4e58\u6cd5\u8fd0\u7b97\u3002\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u9009\u62e9\u5176\u4ed6\u6570\u5b57\u3002 <\/p>\n\n\n\n<p class=\"has-background has-medium-font-size has-vivid-cyan-blue-background-color\">5\u3001 public boolean equals(Object obj); <\/p>\n\n\n\n<p>==\u4e0eequals\u5728Java\u4e2d\u7ecf\u5e38\u88ab\u4f7f\u7528\uff0c\u5927\u5bb6\u4e5f\u90fd\u77e5\u9053==\u4e0eequals\u7684\u533a\u522b\uff1a<\/p>\n\n\n\n<p>==\u8868\u793a\u7684\u662f\u53d8\u91cf\u503c\u5b8c\u6210\u76f8\u540c\uff08\u5bf9\u4e8e\u57fa\u7840\u7c7b\u578b\uff0c\u5730\u5740\u4e2d\u5b58\u50a8\u7684\u662f\u503c\uff0c\u5f15\u7528\u7c7b\u578b\u5219\u5b58\u50a8\u6307\u5411\u5b9e\u9645\u5bf9\u8c61\u7684\u5730\u5740\uff09\uff1b<\/p>\n\n\n\n<p>equals\u8868\u793a\u7684\u662f\u5bf9\u8c61\u7684\u5185\u5bb9\u5b8c\u5168\u76f8\u540c\uff0c\u6b64\u5904\u7684\u5185\u5bb9\u591a\u6307\u5bf9\u8c61\u7684\u7279\u5f81\/\u5c5e\u6027\u3002<\/p>\n\n\n\n<p>\u5b9e\u9645\u4e0a\uff0c\u4e0a\u9762\u8bf4\u6cd5\u662f\u4e0d\u4e25\u8c28\u7684\uff0c\u66f4\u591a\u7684\u53ea\u662f\u5e38\u89c1\u4e8eString\u7c7b\u4e2d\u3002\u9996\u5148\u770b\u4e00\u4e0bObject\u7c7b\u4e2d\u5173\u4e8eequals()\u65b9\u6cd5\u7684\u5b9a\u4e49\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public boolean equals(Object obj) {\n    return (this == obj);\n}<\/code><\/pre>\n\n\n\n<p>\u7531\u6b64\u53ef\u89c1\uff0cObject\u539f\u751f\u7684equals()\u65b9\u6cd5\u5185\u90e8\u8c03\u7528\u7684\u6b63\u662f==\uff0c\u4e0e==\u5177\u6709\u76f8\u540c\u7684\u542b\u4e49\u3002\u65e2\u7136\u5982\u6b64\uff0c\u4e3a\u4ec0\u4e48\u8fd8\u8981\u5b9a\u4e49\u6b64equals()\u65b9\u6cd5\uff1f<\/p>\n\n\n\n<p><strong>equlas()\u65b9\u6cd5\u7684\u6b63\u786e\u7406\u89e3\u5e94\u8be5\u662f\uff1a\u5224\u65ad\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u76f8\u7b49\u3002\u90a3\u4e48\u5224\u65ad\u5bf9\u8c61\u76f8\u7b49\u7684\u6807\u5c3a\u53c8\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n\n\n\n<p>\u5982\u4e0a\uff0c\u5728object\u7c7b\u4e2d\uff0c\u6b64\u6807\u5c3a\u5373\u4e3a==\u3002\u5f53\u7136\uff0c\u8fd9\u4e2a\u6807\u5c3a\u4e0d\u662f\u56fa\u5b9a\u7684\uff0c\u5176\u4ed6\u7c7b\u4e2d\u53ef\u4ee5\u6309\u7167\u5b9e\u9645\u7684\u9700\u8981\u5bf9\u6b64\u6807\u5c3a\u542b\u4e49\u8fdb\u884c\u91cd\u5b9a\u4e49\u3002\u5982String\u7c7b\u4e2d\u5219\u662f\u4f9d\u636e\u5b57\u7b26\u4e32\u5185\u5bb9\u662f\u5426\u76f8\u7b49\u6765\u91cd\u5b9a\u4e49\u4e86\u6b64\u6807\u5c3a\u542b\u4e49\u3002\u5982\u6b64\u53ef\u4ee5\u589e\u52a0\u7c7b\u7684\u529f\u80fd\u578b\u548c\u5b9e\u9645\u7f16\u7801\u7684\u7075\u6d3b\u6027\u3002\u5f53\u7136\u4e86\uff0c\u5982\u679c\u81ea\u5b9a\u4e49\u7684\u7c7b\u6ca1\u6709\u91cd\u5199equals()\u65b9\u6cd5\u6765\u91cd\u65b0\u5b9a\u4e49\u6b64\u6807\u5c3a\uff0c\u90a3\u4e48\u9ed8\u8ba4\u7684\u5c06\u662f\u5176\u7236\u7c7b\u7684equals()\uff0c\u76f4\u5230object\u57fa\u7c7b\u3002<\/p>\n\n\n\n<p>\u5982\u4e0b\u573a\u666f\u7684\u5b9e\u9645\u4e1a\u52a1\u9700\u6c42\uff0c\u5bf9\u4e8eUser bean\uff0c\u7531\u5b9e\u9645\u7684\u4e1a\u52a1\u9700\u6c42\u53ef\u77e5\u5f53\u5c5e\u6027uid\u76f8\u540c\u65f6\uff0c\u8868\u793a\u7684\u662f\u540c\u4e00\u4e2aUser\uff0c\u5373\u4e24\u4e2aUser\u5bf9\u8c61\u76f8\u7b49\u3002\u5219\u53ef\u4ee5\u91cd\u5199equals\u4ee5\u91cd\u5b9a\u4e49User\u5bf9\u8c61\u76f8\u7b49\u7684\u6807\u5c3a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.corn.objectsummary;\n\npublic class User {\n\n    private int uid;\n    private String name;\n    private int age;\n\n    public int getUid() {\n        return uid;\n    }\n\n    public void setUid(int uid) {\n        this.uid = uid;\n    }\n\n    protected String getName() {\n        return name;\n    }\n\n    public void setName(String name) {\n        this.name = name;\n    }\n\n    public int getAge() {\n        return age;\n    }\n\n    public void setAge(int age) {\n        this.age = age;\n    }\n\n    @Override\n    public boolean equals(Object obj) {\n        if (obj == null || !(obj instanceof User)) {\n            return false;\n        }\n        if (((User) obj).getUid() == this.getUid()) {\n            return true;\n        }\n        return false;\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.corn.objectsummary;\n\npublic class ObjectTest implements Cloneable {\n\n    public static void main(String[] args) {\n        User u1 = new User();\n        u1.setUid(111);\n        u1.setName(\"\u5f20\u4e09\");\n\n        User u2 = new User();\n        u2.setUid(111);\n        u2.setName(\"\u5f20\u4e09\u4e30\");\n\n        System.out.println(u1.equals(u2)); \/\/\u8fd4\u56detrue\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>ObjectTest\u4e2d\u6253\u5370\u51fatrue\uff0c\u56e0\u4e3aUser\u7c7b\u5b9a\u4e49\u4e2d\u91cd\u5199\u4e86equals()\u65b9\u6cd5\uff0c\u8fd9\u5f88\u597d\u7406\u89e3\uff0c\u5f88\u53ef\u80fd\u5f20\u4e09\u662f\u4e00\u4e2a\u4eba\u5c0f\u540d\uff0c\u5f20\u4e09\u4e30\u624d\u662f\u5176\u5927\u540d\uff0c\u5224\u65ad\u8fd9\u4e24\u4e2a\u4eba\u662f\u4e0d\u662f\u540c\u4e00\u4e2a\u4eba\uff0c\u8fd9\u65f6\u53ea\u7528\u5224\u65aduid\u662f\u5426\u76f8\u540c\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u5982\u4e0a\u91cd\u5199equals\u65b9\u6cd5\u8868\u9762\u4e0a\u770b\u4e0a\u53bb\u662f\u53ef\u4ee5\u4e86\uff0c\u5b9e\u5219\u4e0d\u7136\u3002\u56e0\u4e3a\u5b83\u7834\u574f\u4e86Java\u4e2d\u7684\u7ea6\u5b9a\uff1a<strong>\u91cd\u5199equals()\u65b9\u6cd5\u5fc5\u987b\u91cd\u5199hasCode()\u65b9\u6cd5\u3002<\/strong><\/p>\n\n\n\n<p class=\"has-background has-medium-font-size has-vivid-cyan-blue-background-color\">6\u3001protected native Object clone() throws CloneNotSupportedException;<\/p>\n\n\n\n<p>clone()\u65b9\u6cd5\u53c8\u662f\u4e00\u4e2a\u88ab\u58f0\u660e\u4e3anative\u7684\u65b9\u6cd5\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u77e5\u9053\u4e86clone()\u65b9\u6cd5\u5e76\u4e0d\u662fJava\u7684\u539f\u751f\u65b9\u6cd5\uff0c\u5177\u4f53\u7684\u5b9e\u73b0\u662f\u6709C\/C++\u5b8c\u6210\u7684\u3002clone\u82f1\u6587\u7ffb\u8bd1\u4e3a\"\u514b\u9686\"\uff0c\u5176\u76ee\u7684\u662f\u521b\u5efa\u5e76\u8fd4\u56de\u6b64\u5bf9\u8c61\u7684\u4e00\u4e2a\u526f\u672c\u3002\u5f62\u8c61\u70b9\u7406\u89e3\uff0c\u8fd9\u6709\u4e00\u8f86\u79d1\u9c81\u5179\uff0c\u4f60\u770b\u7740\u4e0d\u9519\uff0c\u60f3\u8981\u4e2a\u4e00\u6a21\u4e00\u6837\u7684\u3002\u4f60\u8c03\u7528\u6b64\u65b9\u6cd5\u5373\u53ef\u50cf\u53d8\u9b54\u672f\u4e00\u6837\u53d8\u51fa\u4e00\u8f86\u4e00\u6a21\u4e00\u6837\u7684\u79d1\u9c81\u5179\u51fa\u6765\u3002\u914d\u7f6e\u4e00\u6837\uff0c\u957f\u76f8\u4e00\u6837\u3002\u4f46\u4ece\u6b64\u523b\u8d77\uff0c\u539f\u6765\u7684\u90a3\u8f86\u79d1\u9c81\u5179\u5982\u679c\u8fdb\u884c\u4e86\u65b0\u7684\u88c5\u9970\uff0c\u4e0e\u4f60\u514b\u9686\u51fa\u6765\u7684\u8fd9\u8f86\u79d1\u9c81\u5179\u6ca1\u6709\u4efb\u4f55\u5173\u7cfb\u4e86\u3002\u4f60\u514b\u9686\u51fa\u6765\u7684\u5bf9\u8c61\u53d8\u4e0d\u53d8\u5b8c\u5168\u5728\u4e8e\u4f60\u5bf9\u514b\u9686\u51fa\u6765\u7684\u79d1\u9c81\u5179\u6709\u6ca1\u6709\u8fdb\u884c\u8fc7\u4ec0\u4e48\u64cd\u4f5c\u4e86\u3002Java\u672f\u8bed\u8868\u8ff0\u4e3a\uff1a<strong>clone\u51fd\u6570\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5f15\u7528\uff0c\u6307\u5411\u7684\u662f\u65b0\u7684clone\u51fa\u6765\u7684\u5bf9\u8c61\uff0c\u6b64\u5bf9\u8c61\u4e0e\u539f\u5bf9\u8c61\u5206\u522b\u5360\u7528\u4e0d\u540c\u7684\u5806\u7a7a\u95f4\u3002<\/strong><\/p>\n\n\n\n<p>\u660e\u767d\u4e86clone\u7684\u542b\u4e49\u540e\uff0c\u63a5\u4e0b\u6765\u770b\u770b\u5982\u679c\u8c03\u7528clone()\u51fd\u6570\u5bf9\u8c61\u8fdb\u884c\u6b64\u514b\u9686\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u770b\u4e00\u4e0b\u4e0b\u9762\u7684\u8fd9\u4e2a\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.corn.objectsummary;\n\nimport com.corn.Person;\n\npublic class ObjectTest {\n\n    public static void main(String[] args) {\n\n        Object o1 = new Object();\n        \/\/ The method clone() from the type Object is not visible\n        Object clone = o1.clone();\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>\u4f8b\u5b50\u5f88\u7b80\u5355\uff0c\u5728main()\u65b9\u6cd5\u4e2d\uff0cnew\u4e00\u4e2aOject\u5bf9\u8c61\u540e\uff0c\u60f3\u76f4\u63a5\u8c03\u7528\u6b64\u5bf9\u8c61\u7684clone\u65b9\u6cd5\u514b\u9686\u4e00\u4e2a\u5bf9\u8c61\uff0c\u4f46\u662f\u51fa\u73b0\u9519\u8bef\u63d0\u793a\uff1a\"The method clone() from the type Object is not visible\"<\/p>\n\n\n\n<p>why? \u6839\u636e\u63d0\u793a\uff0c\u7b2c\u4e00\u53cd\u5e94\u662fObjectTest\u7c7b\u4e2d\u5b9a\u4e49\u7684Oject\u5bf9\u8c61\u65e0\u6cd5\u8bbf\u95ee\u5176clone()\u65b9\u6cd5\u3002\u56de\u5230Object\u7c7b\u4e2dclone()\u65b9\u6cd5\u7684\u5b9a\u4e49\uff0c\u53ef\u4ee5\u770b\u5230\u5176\u88ab\u58f0\u660e\u4e3aprotected\uff0c\u4f30\u8ba1\u95ee\u9898\u5c31\u5728\u8fd9\u4e0a\u9762\u4e86\uff0cprotected\u4fee\u9970\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\u8868\u793a\uff1a<strong>\u5728\u540c\u4e00\u4e2a\u5305\u5185\u6216\u8005\u4e0d\u540c\u5305\u7684\u5b50\u7c7b\u53ef\u4ee5\u8bbf\u95ee\u3002<\/strong>\u663e\u7136\uff0cObject\u7c7b\u4e0eObjectTest\u7c7b\u5728\u4e0d\u540c\u7684\u5305\u4e2d\uff0c\u4f46\u662fObjectTest\u7ee7\u627f\u81eaObject\uff0c\u662fObject\u7c7b\u7684\u5b50\u7c7b\uff0c\u4e8e\u662f\uff0c\u73b0\u5728\u5374\u51fa\u73b0\u5b50\u7c7b\u4e2d\u901a\u8fc7Object\u5f15\u7528\u4e0d\u80fd\u8bbf\u95eeprotected\u65b9\u6cd5\uff0c\u539f\u56e0\u5728\u4e8e\u5bf9\"\u4e0d\u540c\u5305\u4e2d\u7684\u5b50\u7c7b\u53ef\u4ee5\u8bbf\u95ee\"\u6ca1\u6709\u6b63\u786e\u7406\u89e3\u3002<\/p>\n\n\n\n<p><strong>\"\u4e0d\u540c\u5305\u4e2d\u7684\u5b50\u7c7b\u53ef\u4ee5\u8bbf\u95ee\"\uff0c\u662f\u6307\u5f53\u4e24\u4e2a\u7c7b\u4e0d\u5728\u540c\u4e00\u4e2a\u5305\u4e2d\u7684\u65f6\u5019\uff0c\u7ee7\u627f\u81ea\u7236\u7c7b\u7684\u5b50\u7c7b\u5185\u90e8\u4e14\u4e3b\u8c03\uff08\u8c03\u7528\u8005\uff09\u4e3a\u5b50\u7c7b\u7684\u5f15\u7528\u65f6\u624d\u80fd\u8bbf\u95ee\u7236\u7c7b\u7528protected\u4fee\u9970\u7684\u6210\u5458\uff08\u5c5e\u6027\/\u65b9\u6cd5\uff09\u3002 \u5728\u5b50\u7c7b\u5185\u90e8\uff0c\u4e3b\u8c03\u4e3a\u7236\u7c7b\u7684\u5f15\u7528\u65f6\u5e76\u4e0d\u80fd\u8bbf\u95ee\u6b64protected\u4fee\u9970\u7684\u6210\u5458\u3002\uff01\uff08super\u5173\u952e\u5b57\u9664\u5916\uff09<\/strong><\/p>\n\n\n\n<p>\u4e8e\u662f\uff0c\u4e0a\u4f8b\u6539\u6210\u5982\u4e0b\u5f62\u5f0f\uff0c\u6211\u4eec\u53d1\u73b0\uff0c\u53ef\u4ee5\u6b63\u5e38\u7f16\u8bd1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.corn.objectsummary;\n\n\npublic class ObjectTest {\n\n    public static void main(String[] args) {\n        ObjectTest ot1 = new ObjectTest();\n\n        try {\n            ObjectTest ot2 = (ObjectTest) ot1.clone();\n        } catch (CloneNotSupportedException e) {\n            \/\/ TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>\u662f\u7684\uff0c\u56e0\u4e3a\u6b64\u65f6\u7684\u4e3b\u8c03\u5df2\u7ecf\u662f\u5b50\u7c7b\u7684\u5f15\u7528\u4e86\u3002<\/p>\n\n\n\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4f1a\u629b\u51fa\"java.lang.CloneNotSupportedException\",\u8868\u660eclone()\u65b9\u6cd5\u5e76\u672a\u6b63\u786e\u6267\u884c\u5b8c\u6bd5\uff0c\u95ee\u9898\u7684\u539f\u56e0\u5728\u4e0eJava\u4e2d\u7684\u8bed\u6cd5\u89c4\u5b9a\uff1a<\/p>\n\n\n\n<p>clone()\u7684\u6b63\u786e\u8c03\u7528\u662f\u9700\u8981\u5b9e\u73b0Cloneable\u63a5\u53e3\uff0c\u5982\u679c\u6ca1\u6709\u5b9e\u73b0Cloneable\u63a5\u53e3\uff0c\u5e76\u4e14\u5b50\u7c7b\u76f4\u63a5\u8c03\u7528Object\u7c7b\u7684clone()\u65b9\u6cd5\uff0c\u5219\u4f1a\u629b\u51faCloneNotSupportedException\u5f02\u5e38\u3002<\/p>\n\n\n\n<p>Cloneable\u63a5\u53e3\u4ec5\u662f\u4e00\u4e2a\u8868\u793a\u63a5\u53e3\uff0c\u63a5\u53e3\u672c\u8eab\u4e0d\u5305\u542b\u4efb\u4f55\u65b9\u6cd5\uff0c\u7528\u6765\u6307\u793aObject.clone()\u53ef\u4ee5\u5408\u6cd5\u7684\u88ab\u5b50\u7c7b\u5f15\u7528\u6240\u8c03\u7528\u3002<\/p>\n\n\n\n<p>\u4e8e\u662f\uff0c\u4e0a\u8ff0\u4ee3\u7801\u6539\u6210\u5982\u4e0b\u5f62\u5f0f\uff0c\u5373\u53ef\u6b63\u786e\u6307\u5b9aclone()\u65b9\u6cd5\u4ee5\u5b9e\u73b0\u514b\u9686\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.corn.objectsummary;\n\npublic class ObjectTest implements Cloneable {\n\n    public static void main(String[] args) {\n\n        ObjectTest ot1 = new ObjectTest();\n\n        try {\n            ObjectTest ot2 = (ObjectTest) ot1.clone();\n            System.out.println(\"ot2:\" + ot2);\n        } catch (CloneNotSupportedException e) {\n            \/\/ TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n    }\n\n}<\/code><\/pre>\n\n\n\n<p class=\"has-background has-medium-font-size has-vivid-cyan-blue-background-color\">7\u3001public String toString()<\/p>\n\n\n\n<p>toString()\u65b9\u6cd5\u8fd4\u56de\u8be5\u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u8868\u793a\u3002\u5148\u770b\u4e00\u4e0bObject\u4e2d\u7684\u5177\u4f53\u65b9\u6cd5\u4f53\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public String toString() {\n    return getClass().getName() + \"@\" + Integer.toHexString(hashCode());\n}<\/code><\/pre>\n\n\n\n<p>toString()\u65b9\u6cd5\u76f8\u4fe1\u5927\u5bb6\u90fd\u7ecf\u5e38\u7528\u5230\uff0c\u5373\u4f7f\u6ca1\u6709\u663e\u5f0f\u8c03\u7528\uff0c\u4f46\u5f53\u6211\u4eec\u4f7f\u7528System.out.println(obj)\u65f6\uff0c\u5176\u5185\u90e8\u4e5f\u662f\u901a\u8fc7toString()\u6765\u5b9e\u73b0\u7684\u3002<\/p>\n\n\n\n<p>getClass()\u8fd4\u56de\u5bf9\u8c61\u7684\u7c7b\u5bf9\u8c61\uff0cgetClassName()\u4ee5String\u5f62\u5f0f\u8fd4\u56de\u7c7b\u5bf9\u8c61\u7684\u540d\u79f0\uff08\u542b\u5305\u540d\uff09\u3002Integer.toHexString(hashCode())\u5219\u662f\u4ee5\u5bf9\u8c61\u7684\u54c8\u5e0c\u7801\u4e3a\u5b9e\u53c2\uff0c\u4ee516\u8fdb\u5236\u65e0\u7b26\u53f7\u6574\u6570\u5f62\u5f0f\u8fd4\u56de\u6b64\u54c8\u5e0c\u7801\u7684\u5b57\u7b26\u4e32\u8868\u793a\u5f62\u5f0f\u3002<\/p>\n\n\n\n<p>\u5982\u4e0a\u4f8b\u4e2d\u7684u1\u7684\u54c8\u5e0c\u7801\u662f638\uff0c\u5219\u5bf9\u5e94\u768416\u8fdb\u5236\u4e3a27e\uff0c\u8c03\u7528toString()\u65b9\u6cd5\u8fd4\u56de\u7684\u7ed3\u679c\u4e3a\uff1acom.corn.objectsummary.User@27e\u3002<\/p>\n\n\n\n<p><strong>\u56e0\u6b64\uff1atoString()\u662f\u7531\u5bf9\u8c61\u7684\u7c7b\u578b\u548c\u5176\u54c8\u5e0c\u7801\u552f\u4e00\u786e\u5b9a\uff0c\u540c\u4e00\u7c7b\u578b\u4f46\u4e0d\u76f8\u7b49\u7684\u4e24\u4e2a\u5bf9\u8c61\u5206\u522b\u8c03\u7528toString()\u65b9\u6cd5\u8fd4\u56de\u7684\u7ed3\u679c\u53ef\u80fd\u76f8\u540c\u3002<\/strong><\/p>\n\n\n\n<p class=\"has-background has-medium-font-size has-vivid-cyan-blue-background-color\"> 8\/9\/10\/11\/12. wait(...) \/ notify() \/ notifyAll() <\/p>\n\n\n\n<p>\u4e00\u8bf4\u5230wait(...) \/ notify() | notifyAll()\u51e0\u4e2a\u65b9\u6cd5\uff0c\u9996\u5148\u60f3\u5230\u7684\u662f\u7ebf\u7a0b\u3002\u786e\u5b9e\uff0c\u8fd9\u51e0\u4e2a\u65b9\u6cd5\u4e3b\u8981\u7528\u4e8ejava\u591a\u7ebf\u7a0b\u4e4b\u95f4\u7684\u534f\u4f5c\u3002\u5148\u5177\u4f53\u770b\u4e0b\u8fd9\u51e0\u4e2a\u65b9\u6cd5\u7684\u4e3b\u8981\u542b\u4e49\uff1a<\/p>\n\n\n\n<p>wait()\uff1a\u8c03\u7528\u6b64\u65b9\u6cd5\u6240\u5728\u7684\u5f53\u524d\u7ebf\u7a0b\u7b49\u5f85\uff0c\u76f4\u5230\u5728\u5176\u4ed6\u7ebf\u7a0b\u4e0a\u8c03\u7528\u6b64\u65b9\u6cd5\u7684\u4e3b\u8c03\uff08\u67d0\u4e00\u5bf9\u8c61\uff09\u7684notify()\/notifyAll()\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>wait(long timeout)\/wait(long timeout, int nanos)\uff1a\u8c03\u7528\u6b64\u65b9\u6cd5\u6240\u5728\u7684\u5f53\u524d\u7ebf\u7a0b\u7b49\u5f85\uff0c\u76f4\u5230\u5728\u5176\u4ed6\u7ebf\u7a0b\u4e0a\u8c03\u7528\u6b64\u65b9\u6cd5\u7684\u4e3b\u8c03\uff08\u67d0\u4e00\u5bf9\u8c61\uff09\u7684notisfy()\/notisfyAll()\u65b9\u6cd5\uff0c\u6216\u8d85\u8fc7\u6307\u5b9a\u7684\u8d85\u65f6\u65f6\u95f4\u91cf\u3002<\/p>\n\n\n\n<p>notify()\/notifyAll()\uff1a\u5524\u9192\u5728\u6b64\u5bf9\u8c61\u76d1\u89c6\u5668\u4e0a\u7b49\u5f85\u7684\u5355\u4e2a\u7ebf\u7a0b\/\u6240\u6709\u7ebf\u7a0b\u3002<\/p>\n\n\n\n<p>wait(...) \/ notify() | notifyAll()\u4e00\u822c\u60c5\u51b5\u4e0b\u90fd\u662f\u914d\u5957\u4f7f\u7528\u3002\u4e0b\u9762\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.qqyumidi;\n\npublic class ThreadTest {\n\n    \/**\n     * @param args\n     *\/\n    public static void main(String[] args) {\n        \/\/ TODO Auto-generated method stub\n        MyRunnable r = new MyRunnable();\n        Thread t = new Thread(r);\n        t.start();\n        synchronized (r) {\n            try {\n                System.out.println(\"main thread \u7b49\u5f85t\u7ebf\u7a0b\u6267\u884c\u5b8c\");\n                r.wait();\n                System.out.println(\"\u88abnotity\u5524\u9192\uff0c\u5f97\u4ee5\u7ee7\u7eed\u6267\u884c\");\n            } catch (InterruptedException e) {\n                \/\/ TODO Auto-generated catch block\n                e.printStackTrace();\n                System.out.println(\"main thread \u672c\u60f3\u7b49\u5f85\uff0c\u4f46\u88ab\u610f\u5916\u6253\u65ad\u4e86\");\n            }\n            System.out.println(\"\u7ebf\u7a0bt\u6267\u884c\u76f8\u52a0\u7ed3\u679c\" + r.getTotal());\n        }\n    }\n}\n\nclass MyRunnable implements Runnable {\n    private int total;\n\n    @Override\n    public void run() {\n        \/\/ TODO Auto-generated method stub\n        synchronized (this) {\n            System.out.println(\"Thread name is:\" + Thread.currentThread().getName());\n            for (int i = 0; i &lt; 10; i++) {\n                total += i;\n            }\n            notify();\n            System.out.println(\"\u6267\u884cnotif\u540e\u540c\u6b65\u4ee3\u7801\u5757\u4e2d\u4f9d\u7136\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\u76f4\u81f3\u5b8c\u6bd5\");\n        }\n        System.out.println(\"\u6267\u884cnotif\u540e\u4e14\u540c\u6b65\u4ee3\u7801\u5757\u5916\u7684\u4ee3\u7801\u6267\u884c\u65f6\u673a\u53d6\u51b3\u4e8e\u7ebf\u7a0b\u8c03\u5ea6\");\n    }\n\n    public int getTotal() {\n        return total;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\n\n\u8fd0\u884c\u7ed3\u679c\u4e3a\uff1a\n\n<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>main thread \u7b49\u5f85t\u7ebf\u7a0b\u6267\u884c\u5b8c\nThread name is:Thread-0\n\u6267\u884cnotif\u540e\u540c\u6b65\u4ee3\u7801\u5757\u4e2d\u4f9d\u7136\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\u76f4\u81f3\u5b8c\u6bd5\n\u6267\u884cnotif\u540e\u4e14\u540c\u6b65\u4ee3\u7801\u5757\u5916\u7684\u4ee3\u7801\u6267\u884c\u65f6\u673a\u53d6\u51b3\u4e8e\u7ebf\u7a0b\u8c03\u5ea6  \/\/\u6b64\u884c\u8f93\u51fa\u4f4d\u7f6e\u6709\u5177\u4f53\u7684JVM\u7ebf\u7a0b\u8c03\u5ea6\u51b3\u5b9a\uff0c\u6709\u53ef\u80fd\u6700\u540e\u6267\u884c\n\u88abnotity\u5524\u9192\uff0c\u5f97\u4ee5\u7ee7\u7eed\u6267\u884c\n\u7ebf\u7a0bt\u6267\u884c\u76f8\u52a0\u7ed3\u679c45<\/code><\/pre>\n\n\n\n<p>\u65e2\u7136\u662f\u4f5c\u7528\u4e8e\u591a\u7ebf\u7a0b\u4e2d\uff0c\u4e3a\u4ec0\u4e48\u5374\u662fObject\u8fd9\u4e2a\u57fa\u7c7b\u6240\u5177\u6709\u7684\u65b9\u6cd5\uff1f\u539f\u56e0\u5728\u4e8e\u7406\u8bba\u4e0a\u4efb\u4f55\u5bf9\u8c61\u90fd\u53ef\u4ee5\u89c6\u4e3a\u7ebf\u7a0b\u540c\u6b65\u4e2d\u7684\u76d1\u542c\u5668\uff0c\u4e14wait(...)\/notify()|notifyAll()\u65b9\u6cd5\u53ea\u80fd\u5728\u540c\u6b65\u4ee3\u7801\u5757\u4e2d\u624d\u80fd\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>&nbsp;\u4ece\u4e0a\u8ff0\u4f8b\u5b50\u7684\u8f93\u51fa\u7ed3\u679c\u4e2d\u53ef\u4ee5\u5f97\u51fa\u5982\u4e0b\u7ed3\u8bba\uff1a<\/p>\n\n\n\n<p>1\u3001wait(...)\u65b9\u6cd5\u8c03\u7528\u540e\u5f53\u524d\u7ebf\u7a0b\u5c06\u7acb\u5373\u963b\u585e\uff0c\u4e14\u9002\u5f53\u5176\u6240\u6301\u6709\u7684\u540c\u6b65\u4ee3\u7801\u5757\u4e2d\u7684\u9501\uff0c\u76f4\u5230\u88ab\u5524\u9192\u6216\u8d85\u65f6\u6216\u6253\u65ad\u540e\u4e14\u91cd\u65b0\u83b7\u53d6\u5230\u9501\u540e\u624d\u80fd\u7ee7\u7eed\u6267\u884c\uff1b<\/p>\n\n\n\n<p>2\u3001notify()\/notifyAll()\u65b9\u6cd5\u8c03\u7528\u540e\uff0c\u5176\u6240\u5728\u7ebf\u7a0b\u4e0d\u4f1a\u7acb\u5373\u91ca\u653e\u6240\u6301\u6709\u7684\u9501\uff0c\u76f4\u5230\u5176\u6240\u5728\u540c\u6b65\u4ee3\u7801\u5757\u4e2d\u7684\u4ee3\u7801\u6267\u884c\u5b8c\u6bd5\uff0c\u6b64\u65f6\u91ca\u653e\u9501\uff0c\u56e0\u6b64\uff0c\u5982\u679c\u5176\u540c\u6b65\u4ee3\u7801\u5757\u540e\u8fd8\u6709\u4ee3\u7801\uff0c\u5176\u6267\u884c\u5219\u4f9d\u8d56\u4e8eJVM\u7684\u7ebf\u7a0b\u8c03\u5ea6\u3002<\/p>\n\n\n\n<p>\u5728Java\u6e90\u7801\u4e2d\uff0c\u53ef\u4ee5\u770b\u5230wait()\u5177\u4f53\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public final void wait() throws InterruptedException {\n        wait(0);\n    }<\/code><\/pre>\n\n\n\n<p>\u4e14wait(long timeout, int nanos)\u65b9\u6cd5\u5b9a\u4e49\u5185\u90e8\u5b9e\u8d28\u4e0a\u4e5f\u662f\u901a\u8fc7\u8c03\u7528wait(long timeout)\u5b8c\u6210\u3002\u800cwait(long timeout)\u662f\u4e00\u4e2anative\u65b9\u6cd5\u3002\u56e0\u6b64\uff0cwait(...)\u65b9\u6cd5\u672c\u8d28\u4e0a\u90fd\u662fnative\u65b9\u5f0f\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>notify()\/notifyAll()\u65b9\u6cd5\u4e5f\u90fd\u662fnative\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"has-background has-medium-font-size has-vivid-cyan-blue-background-color\"> 13\u3001 protected void finalize(); <\/p>\n\n\n\n<p>finalize\u65b9\u6cd5\u4e3b\u8981\u4e0eJava\u5783\u573e\u56de\u6536\u673a\u5236\u6709\u5173\u3002\u9996\u5148\u6211\u4eec\u770b\u4e00\u4e0bfinalized\u65b9\u6cd5\u5728Object\u4e2d\u7684\u5177\u4f53\u5b9a\u4e49\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protected void finalize() throws Throwable { }<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u53d1\u73b0Object\u7c7b\u4e2dfinalize\u65b9\u6cd5\u88ab\u5b9a\u4e49\u6210\u4e00\u4e2a\u7a7a\u65b9\u6cd5\uff0c\u4e3a\u4ec0\u4e48\u8981\u5982\u6b64\u5b9a\u4e49\u5462\uff1ffinalize\u65b9\u6cd5\u7684\u8c03\u7528\u65f6\u673a\u662f\u600e\u4e48\u6837\u7684\u5462\uff1f<\/p>\n\n\n\n<p>\u9996\u5148\uff0cObject\u4e2d\u5b9a\u4e49finalize\u65b9\u6cd5\u8868\u660eJava\u4e2d\u6bcf\u4e00\u4e2a\u5bf9\u8c61\u90fd\u5c06\u5177\u6709finalize\u8fd9\u79cd\u884c\u4e3a\uff0c\u5176\u5177\u4f53\u8c03\u7528\u65f6\u673a\u5728\uff1aJVM\u51c6\u5907\u5bf9\u6b64\u5bf9\u5f62\u8c61\u6240\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u8fdb\u884c\u5783\u573e\u56de\u6536\u524d\uff0c\u5c06\u88ab\u8c03\u7528\u3002\u7531\u6b64\u53ef\u4ee5\u770b\u51fa\uff0c\u6b64\u65b9\u6cd5\u5e76\u4e0d\u662f\u7531\u6211\u4eec\u4e3b\u52a8\u53bb\u8c03\u7528\u7684\uff08\u867d\u7136\u53ef\u4ee5\u4e3b\u52a8\u53bb\u8c03\u7528\uff0c\u6b64\u65f6\u4e0e\u5176\u4ed6\u81ea\u5b9a\u4e49\u65b9\u6cd5\u65e0\u5f02\uff09\u3002<\/p>\n\n\n\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/qtvz.com\/redirect\/aHR0cHM6Ly93d3cuY25ibG9ncy5jb20vbHdicXF5dW1pZGkvcC8zNjkzMDE1Lmh0bWw=\" target=\"_blank\">https:\/\/www.cnblogs.com\/lwbqqyumidi\/p\/3693015.html<\/a><\/p>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"1\u3001\u7c7b\u6784\u9020\u5668public Object(); \u5927\u90e8\u5206\u60c5\u51b5\u4e0b\uff0cJava\u4e2d\u901a\u8fc7\u5f62\u5982 new A(args..)\u5f62\u5f0f\u521b\u5efa\u4e00\u4e2a\u5c5e\u4e8e\u8be5\u7c7b\u578b\u7684\u5bf9\u8c61\u3002\u5176\u4e2dA\u5373\u662f\u7c7b\u540d\uff0cA(args..)\u5373\u6b64\u7c7b\u5b9a\u4e49\u4e2d\u76f8\u5bf9\u5e94\u7684\u6784\u9020\u51fd\u6570\u3002 \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[40],"tags":[69],"views":15015,"_links":{"self":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/246"}],"collection":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/comments?post=246"}],"version-history":[{"count":10,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/246\/revisions"}],"predecessor-version":[{"id":341,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/246\/revisions\/341"}],"wp:attachment":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/media?parent=246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/categories?post=246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/tags?post=246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}