{"id":698,"date":"2019-12-02T09:15:04","date_gmt":"2019-12-02T00:15:04","guid":{"rendered":"http:\/\/www.itchefblog.com\/?p=698"},"modified":"2019-12-30T23:10:21","modified_gmt":"2019-12-30T14:10:21","slug":"kotlin-basics","status":"publish","type":"post","link":"https:\/\/www.itchefblog.com\/?p=698","title":{"rendered":"Kotlin Basics"},"content":{"rendered":"<p>[kt]<br \/>\n\/\/\uc22b\uc790 \ud615\ud0dc\uc758 \ubb38\uc790\uc5f4\uc744 \uc22b\uc790\ub85c \ubc14\uafc0 \ub54c<br \/>\nval intStr = &quot;10&quot;<br \/>\nval str = Integer.patseInt(intStr)<\/p>\n<p>\/\/\uc77c\ubc18 \ud074\ub798\uc2a4\uac04\uc5d0 \ud615\ubcc0\ud658 \uc2dc as \uc0ac\uc6a9<br \/>\nopen class Animal<br \/>\nclass Dog : Animal()<br \/>\nval dog = Dog()<br \/>\nval animal = dog as Animal<\/p>\n<p>\/\/\uc22b\uc790\ud615 \uc790\ub8cc\ub07c\ub9ac \ud615 \ubcc0\ud658<br \/>\nval a = 10L<br \/>\nval b = 20<\/p>\n<p>val c = a.toInt()<br \/>\nval d = b.toDouble()<br \/>\nval e = a.toString()<br \/>\n[\/kt]<\/p>\n<p>[kt]<br \/>\n\/\/\ud615 \uccb4\ud06c, JAVA\uc758 instanceOf \uc5d0 \ud574\ub2f9\u3148<br \/>\nval str = &quot;hello&quot;<\/p>\n<p>if(str is String){<br \/>\n\tprintln(str.toUpperCase())<br \/>\n}<br \/>\n[\/kt]<\/p>\n<p>[kt]<br \/>\n\/\/let() \ud568\uc218<br \/>\n\/\/fun &lt;T, R&gt; T.let(block: (T) -&gt; R): R<br \/>\nval result = str?.let {<br \/>\n\tInteger.parseInt(it)<br \/>\n}<\/p>\n<p>\/\/let \ud568\uc218\ub294 \ube14\ub85d\uc5d0 \uc790\uae30 \uc790\uc2e0\uc744 \uc778\uc218\ub85c \uc804\ub2ec\ud558\uace0 \uc218\ud589\ub41c \uacb0\uacfc\ub97c \ubc18\ud658\ud55c\ub2e4.<br \/>\n\/\/\uc778\uc218\ub85c \uc804\ub2ec\ud55c \uaca9\uccb4\ub294 it\uc73c\ub85c \ucc38\uc870\ud558\uba70, let\uc744 ?.\uacfc \ud568\uaf10 \uc0ac\uc6a9\ud558\uba74 null\uac12\uc774 \uc544\ub2d0 \ub54c\ub9cc \uc2e4\ud589\ud558\ub294 \ucf54\ub4dc\ub97c<br \/>\n\/\/\uc704\uc640 \uac19\uc774 \ub098\ud0c0\ub0bc \uc218 \uc788\ub2e4.<br \/>\n\/\/\uc704 \ucf54\ub4dc\ub294 str\uc774 null\uc774 \uc544\ub2d0 \uacbd\uc6b0\uc5d0\ub9cc \uc815\uc218\ub85c \ubcc0\uacbd\ud558\uc5ec \ucd9c\ub825\ud55c\ub2e4.<br \/>\n[\/kt]<\/p>\n<p>[kt]<br \/>\n\/\/with() \ud568\uc218<br \/>\n\/\/fun &lt;T, R&gt; with(receiver: T, block T.() -&gt; R): R<br \/>\nwith(str){<br \/>\n\tprintln(toUpperCase())<br \/>\n}<br \/>\n\/\/with\ud568\uc218\ub294 \uc778\uc218\ub85c \uac1d\uccb4\ub97c \ubc1b\uace0 \ube14\ub85d\uc5d0 \ub9ac\uc2dc\ubc84 \uac1d\uccb4\ub85c \uc804\ub2ec\ud55c\ub2e4.<br \/>\n\/\/\uc218\ud589\ub41c \uacb0\uacfc\ub97c \ubc18\ud658\ud55c\ub2e4.<br \/>\n\/\/\ub9ac\uc2dc\ubc84 \uac1d\uccb4\ub85c \uc804\ub2ec\ub41c \uac1d\uccb4\ub294 this\ub85c \uc811\uadfc \uac00\ub2a5\ud558\ub2e4.<br \/>\n\/\/this\ub294 \uc0dd\ub7b5\uc774 \uac00\ub2a5\ud558\ubbc0\ub85c \uc704\uc640 \uac19\uc774 \uc791\uc131\uc774 \uac00\ub2a5\ud558\uba70, \uc548\uc804\ud55c \ud638\ucd9c\uc774 \ubd88\uac00\ud558\uc5ec str\uc774 null\uac12\uc774<br \/>\n\/\/\uc544\ub2d0 \uacbd\uc6b0\uc5d0\ub9cc \uc0ac\uc6a9\ud574\uc57c \ud55c\ub2e4.<br \/>\n[\/kt]<\/p>\n<p>[kt]<br \/>\n\/\/apply() \ud568\uc218<br \/>\n\/\/fun &lt;T&gt; T.apply(block: T.() -&gt; Unit): T<br \/>\nval result = car?.apply {<br \/>\n\tcar.setColor(Color.RED)<br \/>\n\tcar.setPrice(1000)<br \/>\n}<br \/>\n\/\/apply\ud568\uc218\ub294 \ube14\ub85d\uc5d0 \uac1d\uccb4 \uc790\uc2e0\uc774 \ub9ac\uc2dc\ubc84 \uac1d\uccb4\ub85c \uc804\ub2ec\ub418\uace0 \uc774 \uac1d\uccb4\uac00 \ubc18\ud658\ub41c\ub2e4.<br \/>\n\/\/\uac1d\uccb4\uc758 \uc0c1\ud0dc\ub97c \ubcc0\ud654\uc2dc\ud0a4\uace0 \uadf8 \uac1d\uccb4\ub97c \ub2e4\uc2dc \ubc18\ud658\ud560 \ub54c \uc8fc\ub85c \uc0ac\uc6a9.<br \/>\n[\/kt]<\/p>\n<p>[kt]<br \/>\n\/\/run() \ud568\uc218<br \/>\n\/\/fun &lt;R&gt; run(block: () -&gt; R): R<br \/>\nval avg = run {<br \/>\n\tval korean = 100<br \/>\n\tval english = 80<br \/>\n\tval math = 50<\/p>\n<p>\t(korean + english + math) \/ 3.0<br \/>\n}<\/p>\n<p>\/\/\uac1d\uccb4\uc5d0\uc11c \ud638\ucd9c\ud558\ub294 \ubc29\ubc95\uc740 \uac1d\uccb4\ub97c \ube14\ub85d\uc758 \ub9ac\uc2dc\ubc84 \uac1d\uccb4\ub85c \uc804\ub2ec\ud558\uace0 \ube14\ub85d\uc758 \uacb0\uacfc\ub97c \ubc18\ud658\ud55c\ub2e4.<br \/>\n\/\/\uc548\uc804\ud55c \ud638\ucd9c\uc744 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc5b4\uc11c with \ud568\uc218\ubcf4\ub2e4 \uc720\uc6a9\ud558\ub2e4.<\/p>\n<p>\/\/fun &lt;T, R&gt; T.run(block: T.() -&gt; R): R<br \/>\nstr?.run {<br \/>\n\tprintln(toUpperCase())<br \/>\n}<br \/>\n[\/kt]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[kt] \/\/\uc22b\uc790 \ud615\ud0dc\uc758 \ubb38\uc790\uc5f4\uc744 \uc22b\uc790\ub85c \ubc14\uafc0 \ub54c val intStr = &quot;10&quot; val str = Integer.patseInt(intStr) \/\/\uc77c\ubc18 \ud074\ub798\uc2a4\uac04\uc5d0 \ud615\ubcc0\ud658 \uc2dc as \uc0ac\uc6a9 open class Animal class Dog : Animal() val dog = Dog() val animal = dog as Animal \/\/\uc22b\uc790\ud615 \uc790\ub8cc\ub07c\ub9ac \ud615 \ubcc0\ud658 val a = 10L val b = 20 val c = a.toInt() val &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[349,7,4],"tags":[],"class_list":["post-698","post","type-post","status-publish","format-standard","hentry","category-kotlin","category-development","category-it"],"_links":{"self":[{"href":"https:\/\/www.itchefblog.com\/index.php?rest_route=\/wp\/v2\/posts\/698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itchefblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itchefblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itchefblog.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itchefblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=698"}],"version-history":[{"count":1,"href":"https:\/\/www.itchefblog.com\/index.php?rest_route=\/wp\/v2\/posts\/698\/revisions"}],"predecessor-version":[{"id":700,"href":"https:\/\/www.itchefblog.com\/index.php?rest_route=\/wp\/v2\/posts\/698\/revisions\/700"}],"wp:attachment":[{"href":"https:\/\/www.itchefblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itchefblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itchefblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}