{"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":"Java \u5909\u6570\u306e\u578b\u3092 instanceof \u3067\u78ba\u8a8d\u3059\u308b"},"content":{"rendered":"<h2 class=\"wp-block-heading\">\ubcc0\uc218\uc758 \uc720\ud615 \ud655\uc778<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\"><em>\ubcc0\uc218<\/em> instanceof \u30af\u30e9\u30b9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\ubcc0\uc218<\/em> instanceof \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9<\/p>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><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 decoding=\"async\" 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 class=\"wp-block-heading\">\uc0d8\ud50c \ud504\ub85c\uadf8\ub7a8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\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 class=\"wp-block-heading\">\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 class=\"wp-block-heading\">\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 class=\"wp-block-paragraph\">\u5909\u6570 i \u306f Integer \u306a\u306e\u3067\u3001\u7d50\u679c\u306f true \u306b\u306a\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u3053\u308c\u3067\u306f\u5f53\u305f\u308a\u524d\u3059\u304e\u3066 instanceof \u304c\u306a\u3093\u306e\u305f\u3081\u306b\u3042\u308b\u304b\u5206\u304b\u306a\u3044\u306e\u3067\u3001\u3082\u3046\u5c11\u3057\u8907\u96d1\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">instanceof \u306e\u52b9\u679c\u7684\u306a\u4f7f\u3044\u65b9<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">instanceof \u306e\u52b9\u679c\u7684\u306a\u4f7f\u3044\u65b9\u306e\u4e00\u3064\u306b\u3001\u305d\u306e\u5909\u6570\u304c\u3069\u306e\u5b50\u30af\u30e9\u30b9\u306a\u306e\u304b\u3092\u5224\u5b9a\u3059\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\uc0d8\ud50c \ucf54\ub4dc<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\uc0d8\ud50c \ucf54\ub4dc\uc5d0\uc11c\ub294 \ub3d9\ubb3c \ud074\ub798\uc2a4 Animal \uacfc, \ub3d9\ubb3c \ud074\ub798\uc2a4\ub97c \uacc4\uc2b9\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 class=\"wp-block-heading\">\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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\"><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 class=\"wp-block-heading\">\ud2b9\uc815 \uc778\ud130\ud398\uc774\uc2a4\uac00 \uad6c\ud604\ub418\uc5c8\ub294\uc9c0 \ud655\uc778<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">instanceof \u306e\u5bfe\u8c61\u3068\u306a\u308b\u5909\u6570\u306b\u3001\u3042\u308b\u7279\u5b9a\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u304c\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070\u3053\u306e\u3088\u3046\u306a\u4f7f\u3044\u65b9\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\uc0d8\ud50c \ucf54\ub4dc<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b21\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3067\u306f\u3001\u4f50\u85e4\u3055\u3093\u3001\u9234\u6728\u3055\u3093\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u3001\u9234\u6728\u3055\u3093\u3060\u3051\u304c\u8eca\u3092\u6301\u3063\u3066\u3044\u308b\u60f3\u5b9a\u3067\u3001\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9 Car \u3092 implements \u3057\u3066\u3044\u307e\u3059\u3002goShopping() \u30e1\u30bd\u30c3\u30c9\u306f\u8cb7\u3044\u7269\u306b\u884c\u304f\u51e6\u7406\u3092\u4eee\u5b9a\u3057\u3066\u3044\u307e\u3059\u304c\u3001Car \u3092 implements \u3057\u3066\u3044\u308b\u304b\u3001instanceof \u3067\u5224\u5b9a\u3057\u3066\u30b3\u30f3\u30bd\u30fc\u30eb\u51fa\u529b\u3092\u5206\u5c90\u3057\u3066\u3044\u307e\u3059\u3002<\/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 class=\"wp-block-heading\">\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 class=\"wp-block-paragraph\">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>\u5909\u6570\u306e\u578b\u3092\u78ba\u8a8d\u3059\u308b Java \u3067\u5909\u6570\u306e\u578b\u3092\u78ba\u8a8d\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002 Java \u306f\u578b\u3092\u660e\u793a\u7684\u306b\u5ba3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9054,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[19],"tags":[],"class_list":["post-4630","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/ko\/wp-json\/wp\/v2\/posts\/4630","targetHints":{"allow":["GET"]}}],"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}]}}