{"id":4630,"date":"2019-10-21T00:55:50","date_gmt":"2019-10-20T15:55:50","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=4630"},"modified":"2023-11-13T01:14:20","modified_gmt":"2023-11-12T16:14:20","slug":"java-instanceof","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/ko\/blog\/java\/java-instanceof","title":{"rendered":"instanceof\ub85c Java \ubcc0\uc218\uc758 \ud0c0\uc785 \ud655\uc778\ud558\uae30"},"content":{"rendered":"<h2>\ubcc0\uc218\uc758 \uc720\ud615 \ud655\uc778<\/h2>\n\n\n\n<p>Java \uc5d0\uc11c \ubcc0\uc218\uc758 \ud615\ud0dc\ub97c \ud655\uc778\ud558\ub294 \uc0d8\ud50c \ud504\ub85c\uadf8\ub7a8\uc744 \uc18c\uac1c\ud569\ub2c8\ub2e4.<\/p>\n\n\n\n<p>Java \ub294 \ud615\ud0dc\ub97c \uba85\uc2dc\uc801\uc73c\ub85c \uc120\uc5b8\ud558\ub294 \uc815\uc801 \ud615\ud0dc \ubd99\uc774 \uc5b8\uc5b4\uc774\ubbc0\ub85c, \uac70\uae30\uae4c\uc9c0 \ud615\ud0dc\ub97c \ud655\uc778\ud560 \uae30\ud68c\ub294 \uc5c6\uc2b5\ub2c8\ub2e4. \uadf8\ub7ec\ub098 \uc0c1\uc18d \uac1c\uccb4\ub97c \uc0ac\uc6a9\ud558\ub294 \uacbd\uc6b0 \ud615\uc2dd \ud655\uc778\uc774 \ud544\uc694\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<p>Java\uc5d0\uc11c \uc720\ud615\uc744 \ud655\uc778\ud558\ub824\uba74 <strong>instanceof<\/strong> \uc5f0\uc0b0\uc790\ub97c \uc0ac\uc6a9\ud574, \ub2e4\uc74c\uacfc \uac19\uc774 \ud074\ub798\uc2a4\ub098 \uc778\ud130\ud398\uc774\uc2a4\uc5d0 \ub300\ud574\uc11c if\ubb38\ub4f1\uc73c\ub85c \ud3c9\uac00\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-big_icon_good\"><div class=\"wp-block-group__inner-container\">\n<p><em>\ubcc0\uc218<\/em> instanceof \ud074\ub798\uc2a4<\/p>\n\n\n\n<p><em>\ubcc0\uc218<\/em> instanceof \uc778\ud130\ud398\uc774\uc2a4<\/p>\n<\/div><\/div>\n\n\n\n<p><strong>instanceof<\/strong> \uc624\ub978\ucabd\uc5d0 \ud074\ub798\uc2a4 \uc774\ub984 \ub610\ub294 \uc778\ud130\ud398\uc774\uc2a4 \uc774\ub984\uc744 \uc9c0\uc815\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<strong>instanceof<\/strong> \uc758 \ubc18\ud658\uac12\uc740 boolean \uc774\uace0, true \ub77c\uba74 \ubcc0\uc218\ub294 \uc9c0\uc815\ud55c \ud074\ub798\uc2a4\ub098 \uc778\ud130\ud398\uc774\uc2a4, \ub77c\uace0 \ud558\uac8c \ub429\ub2c8\ub2e4.<\/p>\n\n\n\n<div class=\"recommend\">\n<p><a href=\"javascript:clickAdd()\">Chat&amp;Messenger<\/a> \ub294 \ube44\uc988\ub2c8\uc2a4 \ucc44\ud305, \uc6f9 \ud68c\uc758, \ud30c\uc77c \uacf5\uc720, \uc77c\uc815 \uad00\ub9ac, \ubb38\uc11c \uad00\ub9ac, \ud68c\uc758\uc2e4 \uc608\uc57d, \uadfc\ud0dc \uad00\ub9ac\ub97c \uc0ac\uc6a9\ud558\uae30 \uc27d\uac8c \ud1b5\ud569\ud55c \uadf8\ub8f9\uc6e8\uc5b4\uc785\ub2c8\ub2e4. \uae30\uc5c5\uc6a9 \ubcf4\uc548\ub3c4 \ub9cc\uc804\uc73c\ub85c,<mark>\ubb34\ub8cc\ub85c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4!<\/mark><\/p>\n<a href=\"javascript:clickAdd()\"><img style=\"margin:10px;box-shadow: var(--swl-box_shadow);\" src=\"\/images\/cam-top-banner.png\" width=\"700\"><\/a>\n<\/div>\n\n\n\n<h2>\uc0d8\ud50c \ud504\ub85c\uadf8\ub7a8<\/h2>\n\n\n\n<p>\uc6b0\uc120 \uac00\uc7a5 \uac04\ub2e8\ud55c \ud328\ud134. \ubcc0\uc218 i\uac00 Integer\uc774\uba74 true \uadf8\ub807\uc9c0 \uc54a\uc73c\uba74 false\ub97c \ubc18\ud658\ud569\ub2c8\ub2e4.<\/p>\n\n\n\n<h4>\uc0d8\ud50c \ucf54\ub4dc<\/h4>\n\n\n\n<div class=\"hcb_wrap\" data-no-translation=\"\"><pre class=\"prism line-numbers lang-java\" data-lang=\"Java\"><code>public static void integerSample() {\n    Integer i = 100;\n    boolean result = i instanceof Integer;\n    System.out.println(result);\n}<\/code><\/pre><\/div>\n\n\n\n<h4>\ucd9c\ub825 \uacb0\uacfc<\/h4>\n\n\n\n<div class=\"hcb_wrap\" data-no-translation=\"\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>true<\/code><\/pre><\/div>\n\n\n\n<p>\ubcc0\uc218 i\ub294 Integer\uc774\ubbc0\ub85c \uacb0\uacfc\ub294 true\uc785\ub2c8\ub2e4. \uadf8\ub7ec\ub098 \uc774\uac83\uc740 \ub108\ubb34 \ub2f9\uc5f0\ud574\uc11c instanceof \uac00 \ubb34\uc5c7\uc744 \uc704\ud574 \uc788\ub294\uc9c0 \ubaa8\ub974\uae30 \ub54c\ubb38\uc5d0 \uc880 \ub354 \ubcf5\uc7a1\ud558\uac8c \ud569\ub2c8\ub2e4.<\/p>\n\n\n\n<h2>instanceof\ub97c \ud6a8\uacfc\uc801\uc73c\ub85c \uc0ac\uc6a9\ud558\ub294 \ubc29\ubc95<\/h2>\n\n\n\n<p>instanceof \uc758 \ud6a8\uacfc\uc801\uc778 \uc0ac\uc6a9\ubc95\uc758 \ud558\ub098\uc5d0, \uadf8 \ubcc0\uc218\uac00 \uc5b4\ub290 \uc544\uc774 \ud074\ub798\uc2a4\uc778\uac00\ub97c \ud310\uc815\ud558\ub294 \uacbd\uc6b0\uac00 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<h4>\uc0d8\ud50c \ucf54\ub4dc<\/h4>\n\n\n\n<p>\uc0d8\ud50c \ucf54\ub4dc\uc5d0\uc11c\ub294 \ub3d9\ubb3c \ud074\ub798\uc2a4 Animal \uacfc, \ub3d9\ubb3c \ud074\ub798\uc2a4\ub97c \uc0c1\uc18d\ud55c Dog \ud074\ub798\uc2a4, Cat \ud074\ub798\uc2a4\ub97c \uc791\uc131\ud574, \uc778\uc2a4\ud134\uc2a4\ub97c \uc791\uc131\ud55c \ud6c4\uc5d0, play \uba54\uc18c\ub4dc\ub0b4\uc5d0\uc11c \ubcc0\uc218\ub97c <strong>instanceof<\/strong> \ub85c \ud310\uc815\ud574 \ucf58\uc194 \ucd9c\ub825\uc744 \ubd84\uae30\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4. <\/p>\n\n\n\n<div class=\"hcb_wrap\" data-no-translation=\"\"><pre class=\"prism line-numbers lang-java\" data-lang=\"Java\"><code>class Animal {} \nclass Dog extends Animal {}\nclass Cat extends Animal {}\n\npublic class Main {\n    public static void main(String[] args) {\n        instanceofSample();\n    }\n    \n    static void instanceofSample() {\n        Animal dog = new Dog();\n        play(dog);\n        Animal cat = new Cat();\n        play(cat);\n    }\n    \n    static void play(Animal animal) {\n        if (animal instanceof Dog) {\n            System.out.println(&quot;\u304a\u6563\u6b69\u3059\u308b&quot;);\n        } else {\n            System.out.println(&quot;\u732b\u3058\u3083\u3089\u3057\u3067\u904a\u3076&quot;);\n        }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h4>\ucd9c\ub825 \uacb0\uacfc<\/h4>\n\n\n\n<div class=\"hcb_wrap\" data-no-translation=\"\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>\u304a\u6563\u6b69\u3059\u308b\n\u732b\u3058\u3083\u3089\u3057\u3067\u904a\u3076<\/code><\/pre><\/div>\n\n\n\n<p>play \uba54\uc18c\ub4dc \ub0b4\uc5d0\uc11c\ub294 \uc778\uc218\uc5d0 \uac74\ub124\ubc1b\uc740 animal \uac00 dog\uc778\uc9c0 cat\uc778\uc9c0 \ubaa8\ub974\ub294 \uac83\uc774 \ud3ec\uc778\ud2b8\uc785\ub2c8\ub2e4.<\/p>\n\n\n\n<p><strong>instanceof<\/strong> \uadf8\ub7fc \uc288\ud37c \ud074\ub798\uc2a4(Animal) \uc548\uc5d0 \ub4e4\uc5b4 \uc788\ub294 \uc11c\ube0c \ud074\ub798\uc2a4\uc758 \uc778\uc2a4\ud134\uc2a4(Dog \ub610\ub294 Cat)\uc640\ub3c4 \uccb4\ud06c\ud560 \uc218 \uc788\uc73c\ubbc0\ub85c, \uc774\ub7f0 \uc0ac\uc6a9\ubc95\ub3c4 \ud560 \uc218 \uc788\ub124\uc694.<\/p>\n\n\n\n<h2>\ud2b9\uc815 \uc778\ud130\ud398\uc774\uc2a4\uac00 \uad6c\ud604\ub418\uc5c8\ub294\uc9c0 \ud655\uc778<\/h2>\n\n\n\n<p>instanceof \uc758 \ub300\uc0c1\uc774 \ub418\ub294 \ubcc0\uc218\uc5d0, \ud2b9\uc815\uc758 \uc778\ud130\ud398\uc774\uc2a4\uac00 \uad6c\ud604\ub418\uace0 \uc788\ub294\uc9c0\ub97c \ud655\uc778\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4 \uc774\ub7ec\ud55c \uc0ac\uc6a9\ubc95\uc744 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<h4>\uc0d8\ud50c \ucf54\ub4dc<\/h4>\n\n\n\n<p>\ub2e4\uc74c\uc758 \uc0d8\ud50c \ucf54\ub4dc\uc5d0\uc11c\ub294, \uc0ac\ud1a0\uc528, \uc2a4\uc988\ud0a4\uc528 \ud074\ub798\uc2a4\ub97c \uc791\uc131\ud574, \uc2a4\uc988\ud0a4\uc528\ub9cc\uc774 \ucc28\ub97c \uac00\uc9c0\uace0 \uc788\ub2e4\uace0 \uac00\uc815\ud574, \uc778\ud130\ud398\uc774\uc2a4 Car \ub97c implements \ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4. goShopping() \uba54\uc18c\ub4dc\ub294 \uc1fc\ud551\uc5d0 \uac00\ub294 \ucc98\ub9ac\ub97c \uac00\uc815\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4\ub9cc, Car \ub97c implements \ud558\uace0 \uc788\ub294\uc9c0, instanceof \ub85c \ud310\uc815\ud574 \ucf58\uc194 \ucd9c\ub825\uc744 \ubd84\uae30\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<div class=\"hcb_wrap\" data-no-translation=\"\"><pre class=\"prism line-numbers lang-java\" data-lang=\"Java\"><code>interface Car {}\nclass Sato {}\nclass Suzuki implements Car {}\n\npublic class Main {\n    public static void main(String[] args) throws Exception {\n        instanceofSample();\n    }\n    \n    static void instanceofSample() {\n        Sato sato = new Sato();\n        goShopping(sato);\n\n        Suzuki suzuki = new Suzuki();\n        goShopping(suzuki);\n    }\n    \n    static void goShopping(Object human) {\n        if (human instanceof Car) {\n            System.out.println(&quot;\u8eca\u3067\u884c\u304f&quot;);\n        } else {\n            System.out.println(&quot;\u6b69\u3044\u3066\u884c\u304f&quot;);\n        }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h4>\ucd9c\ub825 \uacb0\uacfc:<\/h4>\n\n\n\n<div class=\"hcb_wrap\" data-no-translation=\"\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>\u6b69\u3044\u3066\u884c\u304f\n\u8eca\u3067\u884c\u304f<\/code><\/pre><\/div>\n\n\n\n<p>Car \uac00 \uad6c\ud604\ub418\uace0 \uc788\ub294 \uacbd\uc6b0\uc640 \uadf8\ub807\uc9c0 \uc54a\uc740 \uacbd\uc6b0\ub85c, \ucc98\ub9ac\uac00 \ubd84\uae30\ud558\uace0 \uc788\ub294 \uac83\uc744 \uc54c \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>","protected":false},"excerpt":{"rendered":"<p>\ubcc0\uc218\uc758 \ud615\ud0dc\ub97c \ud655\uc778\ud55c\ub2e4 Java\ub85c \ubcc0\uc218\uc758 \ud615\ud0dc\ub97c \ud655\uc778\ud558\ub294 \uc0d8\ud50c \ud504\ub85c\uadf8\ub7a8\uc744 \uc18c\uac1c\ud569\ub2c8\ub2e4. Java\ub294 \ud615\uc2dd\uc744 \uba85\uc2dc\uc801\uc73c\ub85c \uc120 [...]<\/p>","protected":false},"author":1,"featured_media":9054,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":""},"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts\/4630"}],"collection":[{"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/comments?post=4630"}],"version-history":[{"count":6,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts\/4630\/revisions"}],"predecessor-version":[{"id":9049,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts\/4630\/revisions\/9049"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/media\/9054"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/media?parent=4630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/categories?post=4630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/tags?post=4630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}