{"id":54,"date":"2021-04-25T15:54:38","date_gmt":"2021-04-25T07:54:38","guid":{"rendered":"http:\/\/112.124.66.68\/?p=54"},"modified":"2021-04-25T15:54:38","modified_gmt":"2021-04-25T07:54:38","slug":"instanceof-%e5%85%b3%e9%94%ae%e5%ad%97%e7%9a%84%e4%bd%9c%e7%94%a8","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2021\/04\/25\/instanceof-%e5%85%b3%e9%94%ae%e5%ad%97%e7%9a%84%e4%bd%9c%e7%94%a8\/","title":{"rendered":"instanceof \u5173\u952e\u5b57\u7684\u4f5c\u7528"},"content":{"rendered":"<p>instanceof \u4e25\u683c\u6765\u8bf4\u662fJava\u4e2d\u7684\u4e00\u4e2a\u53cc\u76ee\u8fd0\u7b97\u7b26\uff0c\u7528\u6765\u6d4b\u8bd5\u4e00\u4e2a\u5bf9\u8c61\u662f\u5426\u4e3a\u4e00\u4e2a\u7c7b\u7684\u5b9e\u4f8b\uff0c\u7528\u6cd5\u4e3a\uff1a<\/p>\n<pre>boolean result = obj instanceof Class<\/pre>\n<p>\u5176\u4e2d obj \u4e3a\u4e00\u4e2a\u5bf9\u8c61\uff0cClass \u8868\u793a\u4e00\u4e2a\u7c7b\u6216\u8005\u4e00\u4e2a\u63a5\u53e3\uff0c\u5f53 obj \u4e3a Class \u7684\u5bf9\u8c61\uff0c\u6216\u8005\u662f\u5176\u76f4\u63a5\u6216\u95f4\u63a5\u5b50\u7c7b\uff0c\u6216\u8005\u662f\u5176\u63a5\u53e3\u7684\u5b9e\u73b0\u7c7b\uff0c\u7ed3\u679cresult \u90fd\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56defalse\u3002<!--more--><br \/>\n\u6ce8\u610f\uff1a\u7f16\u8bd1\u5668\u4f1a\u68c0\u67e5 obj \u662f\u5426\u80fd\u8f6c\u6362\u6210\u53f3\u8fb9\u7684class\u7c7b\u578b\uff0c\u5982\u679c\u4e0d\u80fd\u8f6c\u6362\u5219\u76f4\u63a5\u62a5\u9519\uff0c\u5982\u679c\u4e0d\u80fd\u786e\u5b9a<br \/>\n\u7c7b\u578b\uff0c\u5219\u901a\u8fc7\u7f16\u8bd1\uff0c\u5177\u4f53\u770b\u8fd0\u884c\u65f6\u786e\u5b9a<\/p>\n<pre>int i = 0;\nSystem.out.println(i instanceof Integer);\n\/\/\u7f16\u8bd1\u4e0d\u901a\u8fc7 i\u5fc5\u987b\u662f\u5f15\u7528\u7c7b\u578b\uff0c\u4e0d\u80fd\u662f\u57fa\u672c\u7c7b\u578b\nSystem.out.println(i instanceof Object);\/\/\u7f16\u8bd1\u4e0d\u901a\u8fc7<\/pre>\n<pre>Integer integer = new Integer(1);\nSystem.out.println(integer instanceof Integer);\/\/true\n\n\/\/false ,\u5728 JavaSE\u89c4\u8303 \u4e2d\u5bf9 instanceof \u8fd0\u7b97\u7b26\u7684\u89c4\u5b9a\u5c31\u662f\uff1a\n\/\/\u5982\u679c obj \u4e3a null\uff0c\u90a3\u4e48\u5c06\u8fd4\u56defalse\u3002\nSystem.out.println(null instanceof Object);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>instanceof \u4e25\u683c\u6765\u8bf4\u662f&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":325,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-54","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/325"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}