{"id":286822,"date":"2017-05-24T20:05:03","date_gmt":"2017-05-24T16:05:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=286822"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=286822","title":{"rendered":"\u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 Kotlin"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/4d7\/668\/8cd\/4d76688cd52744f2bd7d1f711f6a3e04.jpg\"\/><\/p>\n<p>  <\/p>\n<p>\u0425\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u043e \u043d\u043e\u0432\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Kotlin, \u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0441\u0432\u043e\u0451\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u0420\u0430\u043d\u044c\u0448\u0435 \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u043b Java, \u043d\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0433\u043e\u0434 \u043f\u0438\u0448\u0443 \u043d\u0430 Kotlin \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e. \u0418 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0441\u0435\u0431\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043b\u0443\u0447\u0448\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0442\u044c Java.<\/p>\n<p>  <\/p>\n<p>Kotlin \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0432 <a href=\"https:\/\/www.jetbrains.com\/\">JetBrains<\/a>, \u0438 \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0442\u0435\u0445 \u0436\u0435 \u043b\u044e\u0434\u0435\u0439 \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 <a href=\"https:\/\/www.jetbrains.com\/products.html?fromMenu#type=ide\">IDE<\/a>, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <strong>IntelliJ<\/strong> \u0438 <strong>ReSharper<\/strong>, \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043f\u043e \u0441\u0430\u043c\u043e\u043c\u0443 \u044f\u0437\u044b\u043a\u0443. \u041e\u043d <strong>\u043f\u0440\u0430\u0433\u043c\u0430\u0442\u0438\u0447\u0435\u043d<\/strong> \u0438 <strong>\u043a\u0440\u0430\u0442\u043e\u043a<\/strong>, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0447\u0435\u043c\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441.<\/p>\n<p>  <\/p>\n<p>\u0425\u043e\u0442\u044f Kotlin \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/kotlinlang.org\/docs\/tutorials\/javascript\/kotlin-to-javascript\/kotlin-to-javascript.html\">JavaScript<\/a> \u0438 \u0441\u043a\u043e\u0440\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 <a href=\"https:\/\/blog.jetbrains.com\/kotlin\/2017\/04\/kotlinnative-tech-preview-kotlin-without-a-vm\/\">\u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434<\/a>, \u044f \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u0443\u044e\u0441\u044c \u043d\u0430 \u0435\u0433\u043e \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435 \u2014 <strong>JVM<\/strong>.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0447\u0438\u043d, \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 Kotlin (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043b\u0443\u0447\u0430\u0435\u043d):<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"0-sovmestimost-s-java\">0# \u0421\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 Java<\/h2>\n<p>  <\/p>\n<p>Kotlin \u043d\u0430 <strong>100 % \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 Java<\/strong>. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 \u0441\u0432\u043e\u0438\u043c \u0441\u0442\u0430\u0440\u044b\u043c Java-\u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c, \u043d\u043e \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Kotlin. \u0412\u0441\u0435 \u0432\u0430\u0448\u0438 \u043b\u044e\u0431\u0438\u043c\u044b\u0435 <strong>Java-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b<\/strong>, \u0438, \u0432 \u043a\u0430\u043a\u043e\u043c \u0431\u044b \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0432\u044b \u043d\u0438 \u043f\u0438\u0441\u0430\u043b\u0438, Kotlin \u0431\u0443\u0434\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0438\u043d\u044f\u0442 \u0443\u043f\u0440\u044f\u043c\u044b\u043c \u043b\u044e\u0431\u0438\u0442\u0435\u043b\u0435\u043c Java.<\/p>\n<p>  <\/p>\n<h2 id=\"1-znakomyy-sintaksis\">1# \u0417\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441<\/h2>\n<p>  <\/p>\n<p>Kotlin \u2014 \u043d\u0435 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0442\u0430\u043c \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439 \u044f\u0437\u044b\u043a, \u0440\u043e\u0436\u0434\u0451\u043d\u043d\u044b\u0439 \u0432 \u0430\u043a\u0430\u0434\u0435\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0440\u0443\u0433\u0430\u0445. \u0415\u0433\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0437\u043d\u0430\u043a\u043e\u043c \u043b\u044e\u0431\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443, \u0432\u043e\u0441\u043f\u0438\u0442\u0430\u043d\u043d\u043e\u043c\u0443 \u043d\u0430 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435 \u041e\u041e\u041f, \u0438 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0435\u0441\u0442\u044c <em>\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435<\/em> \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0442 Java \u0432\u0440\u043e\u0434\u0435 \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0438\u043b\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 <code>val var<\/code>. \u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430:<\/p>\n<p>  <\/p>\n<pre><code>class Foo {      val b: String = &quot;b&quot;     \/\/ val means unmodifiable     var i: Int = 0          \/\/ var means modifiable      fun hello() {         val str = &quot;Hello&quot;         print(&quot;$str World&quot;)     }      fun sum(x: Int, y: Int): Int {         return x + y     }      fun maxOf(a: Float, b: Float) = if (a &gt; b) a else b  }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"2-interpolyaciya-strokhttpskotlinlangorgdocsreferencebasic-typeshtmlstring-templates\">2# <a href=\"https:\/\/kotlinlang.org\/docs\/reference\/basic-types.html#string-templates\">\u0418\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u044f \u0441\u0442\u0440\u043e\u043a<\/a><\/h2>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043a\u0430\u043a \u0431\u044b \u0431\u043e\u043b\u0435\u0435 \u0443\u043c\u043d\u0430\u044f \u0438 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f <code>String.format()<\/code> \u0438\u0437 Java, \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0432 \u044f\u0437\u044b\u043a:<\/p>\n<p>  <\/p>\n<pre><code>val x = 4 val y = 7 print(&quot;sum of $x and $y is ${x + y}&quot;)  \/\/ sum of 4 and 7 is 11<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"3-vyvedenie-tipa\">3# \u0412\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430<\/h2>\n<p>  <\/p>\n<p>Kotlin \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u0430\u0448\u0438 \u0442\u0438\u043f\u044b, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code>val a = &quot;abc&quot;                         \/\/ type inferred to String val b = 4                             \/\/ type inferred to Int  val c: Double = 0.7                   \/\/ type declared explicitly val d: List&lt;String&gt; = ArrayList()     \/\/ type declared explicitly<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"4-umnye-privedeniya-tipov-smart-casts\">4# \u0423\u043c\u043d\u044b\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 (Smart Casts)<\/h2>\n<p>  <\/p>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 Kotlin \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0430\u0448\u0443 \u043b\u043e\u0433\u0438\u043a\u0443 \u0438 <strong>\u043f\u043e \u043c\u0435\u0440\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432<\/strong>, \u0442. \u0435. \u0432\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 <code>instanceof<\/code> \u043f\u043e\u0441\u043b\u0435 \u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0439:<\/p>\n<p>  <\/p>\n<pre><code>if (obj is String) {     print(obj.toUpperCase())     \/\/ obj is now known to be a String }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"5-intuitivnye-ravenstva-intuitive-equals\">5# \u0418\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u044b\u0435 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 (Intuitive Equals)<\/h2>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044f\u0432\u043d\u043e <code>equals()<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>==<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e\u0435 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e:<\/p>\n<p>  <\/p>\n<pre><code>val john1 = Person(&quot;John&quot;) val john2 = Person(&quot;John&quot;) john1 == john2    \/\/ true  (structural equality) john1 === john2   \/\/ false (referential equality)<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"6-argumenty-po-umolchaniyu\">6# \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/h2>\n<p>  <\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code>fun build(title: String, width: Int = 800, height: Int = 600) {     Frame(title, width, height) }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"7-imenovannye-argumenty\">7# \u0418\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b<\/h2>\n<p>  <\/p>\n<p>\u0412 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D1%82%D1%80%D0%BE%D0%B8%D1%82%D0%B5%D0%BB%D1%8C_(%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F)\">\u0421\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u0435\u0439<\/a>:<\/p>\n<p>  <\/p>\n<pre><code>build(&quot;PacMan&quot;, 400, 300)                           \/\/ equivalent build(title = &quot;PacMan&quot;, width = 400, height = 300)  \/\/ equivalent build(width = 400, height = 300, title = &quot;PacMan&quot;)  \/\/ equivalent<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"8-vyrazhenie-when\">8# \u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 When<\/h2>\n<p>  <\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043c\u0435\u043d\u0451\u043d \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u0433\u0438\u0431\u043a\u0438\u043c \u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c <em>when<\/em>:<\/p>\n<p>  <\/p>\n<pre><code>when (x) {     1 -&gt; print(&quot;x is 1&quot;)     2 -&gt; print(&quot;x is 2&quot;)     3, 4 -&gt; print(&quot;x is 3 or 4&quot;)     in 5..10 -&gt; print(&quot;x is 5, 6, 7, 8, 9, or 10&quot;)     else -&gt; print(&quot;x is out of range&quot;) }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u043a\u0430\u043a \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 (expression), \u0438 \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 (statement), \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0438\u043b\u0438 \u0431\u0435\u0437 \u043d\u0435\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code>val res: Boolean = when {     obj == null -&gt; false     obj is String -&gt; true     else -&gt; throw IllegalStateException() }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"9-svoystva\">9# \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430<\/h2>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u043c \u043f\u043e\u043b\u044f\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 set &amp; get, \u0442. \u0435. \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0442\u044c \u043d\u0430\u0431\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0431\u0435\u0437\u0443\u043c\u043d\u044b\u043c\u0438 <a href=\"http:\/\/stackoverflow.com\/questions\/1568091\/why-use-getters-and-setters\">\u0433\u0435\u0442\u0442\u0435\u0440\u0430\u043c\u0438 \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u0430\u043c\u0438<\/a>.<\/p>\n<p>  <\/p>\n<pre><code>class Frame {     var width: Int = 800     var height: Int = 600      val pixels: Int         get() = width * height }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"10-data-class\">10# Data Class<\/h2>\n<p>  <\/p>\n<p>\u041e\u043d \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d POJO-\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 <code>toString()<\/code>, <code>equals()<\/code>, <code>hashCode()<\/code> \u0438 <code>copy()<\/code>, \u043d\u043e, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 Java, \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 100 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code>data class Person(val name: String,                   var email: String,                   var age: Int)  val john = Person(&quot;John&quot;, &quot;john@gmail.com&quot;, 112)<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"11-peregruzka-operatora-operator-overloading\">11# \u041f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 (Operator Overloading)<\/h2>\n<p>  <\/p>\n<p>\u0417\u0430\u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<pre><code>data class Vec(val x: Float, val y: Float) {     operator fun plus(v: Vec) = Vec(x + v.x, y + v.y) }  val v = Vec(2f, 3f) + Vec(4f, 1f)<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"12-destrukturiruyuschie-obyavleniya-destructuring-declarations\">12# \u0414\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f (Destructuring Declarations)<\/h2>\n<p>  <\/p>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u0447\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f map:<\/p>\n<p>  <\/p>\n<pre><code>for ((key, value) in map) {     print(&quot;Key: $key&quot;)     print(&quot;Value: $value&quot;) }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"13-diapazony-ranges\">13# \u0414\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b (Ranges)<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<pre><code>for (i in 1..100) { ... }  for (i in 0 until 100) { ... } for (i in 2..10 step 2) { ... }  for (i in 10 downTo 1) { ... }  if (x in 1..10) { ... }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"14-funkcii-rasshireniya-extension-functions\">14# \u0424\u0443\u043d\u043a\u0446\u0438\u0438-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f (Extension Functions)<\/h2>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u043d\u0438\u0442\u0435 \u0441\u0432\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>List<\/code> \u0432 Java? \u0412\u0430\u043c \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>sort()<\/code>, \u0438 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0438\u0437\u0443\u0447\u0430\u0442\u044c <code>Collections.sort()<\/code>. \u041f\u043e\u0437\u0434\u043d\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0431\u0443\u043a\u0432\u044b \u0441\u0442\u0440\u043e\u0447\u043d\u044b\u043c\u0438, \u0432\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u043b\u0438 \u043e <code>StringUtils.capitalize()<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0431\u044b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u0441\u0442\u0430\u0440\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u0442\u043e\u0433\u0434\u0430 \u0432\u0430\u0448 IDE \u043f\u043e\u043c\u043e\u0433 \u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043a\u043e\u0434\u0430. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432 Kotlin:<\/p>\n<p>  <\/p>\n<pre><code>fun String.format(): String {     return this.replace(' ', '_') }  val formatted = str.format()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0445 Java-\u0442\u0438\u043f\u043e\u0432, \u0447\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f <code>String<\/code>:<\/p>\n<p>  <\/p>\n<pre><code>str.removeSuffix(&quot;.txt&quot;) str.capitalize() str.substringAfterLast(&quot;\/&quot;) str.replaceAfter(&quot;:&quot;, &quot;classified&quot;)<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"15-bezopasnost-null\">15# \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c Null<\/h2>\n<p>  <\/p>\n<p>Java \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c <em>\u043f\u043e\u0447\u0442\u0438<\/em> \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u043e \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c. \u0412\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u0438\u043f\u0430 <code>String<\/code> \u043d\u0435 <em>\u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e<\/em> \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <code>String<\/code> \u2014 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 <code>null<\/code>. \u0418 \u0445\u043e\u0442\u044f \u043c\u044b \u043a \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438, \u044d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u043e\u0435 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0438 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 Java-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u044b \u0436\u0438\u0442\u044c \u0432 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u043c \u0441\u0442\u0440\u0430\u0445\u0435 \u043f\u0435\u0440\u0435\u0434 <a href=\"http:\/\/stackoverflow.com\/questions\/218384\/what-is-a-nullpointerexception-and-how-do-i-fix-it\">NPE<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0412 Kotlin \u044d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0435\u043d\u0430 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u0442\u0438\u043f\u044b, <strong>\u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u0435 \u0438 \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null<\/strong>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0442\u0438\u043f\u044b \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 null, \u043d\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u0435, \u0435\u0441\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>?<\/code>:<\/p>\n<p>  <\/p>\n<pre><code>var a: String = &quot;abc&quot; a = null                \/\/ compile error  var b: String? = &quot;xyz&quot; b = null                \/\/ no problem<\/code><\/pre>\n<p>  <\/p>\n<p>Kotlin \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0430\u0441 \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f \u0441 NPE, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0435\u0441\u044c \u043a \u0442\u0438\u043f\u0443, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0435\u043c\u0443 null:<\/p>\n<p>  <\/p>\n<pre><code>val x = b.length        \/\/ compile error: b might be null<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e, \u043d\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0432\u043e\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e. \u0423 \u043d\u0430\u0441 \u0432\u0441\u0451 \u0435\u0449\u0451 \u0435\u0441\u0442\u044c \u0443\u043c\u043d\u044b\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432, \u043a\u043e\u0433\u0434\u0430 \u0442\u0438\u043f\u044b, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u0435 null, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code>if (b == null) return val x = b.length        \/\/ no problem<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 <code>?.<\/code>, \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null \u0432\u043c\u0435\u0441\u0442\u043e \u0431\u0440\u043e\u0441\u0430\u043d\u0438\u044f NPE:<\/p>\n<p>  <\/p>\n<pre><code>val x = b?.length       \/\/ type of x is nullable Int<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0435\u0441\u043b\u0438-\u043d\u0435-null, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u0410 \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0443\u0436\u043d\u043e \u043d\u0435 null-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f elvis-\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>?:<\/code>:<\/p>\n<p>  <\/p>\n<pre><code>val name = ship?.captain?.name ?: &quot;unknown&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u044d\u0442\u043e \u0432\u0430\u043c \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438 \u0432\u0430\u043c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0442\u043e\u0447\u043d\u043e \u043d\u0443\u0436\u043d\u044b NPE, \u0442\u043e \u0441\u043a\u0430\u0436\u0438\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u044f\u0432\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code>val x = b?.length ?: throw NullPointerException()  \/\/ same as below val x = b!!.length                                 \/\/ same as above<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"16-uluchshennye-lyambdy\">16# \u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0435 \u043b\u044f\u043c\u0431\u0434\u044b<\/h2>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043b\u044f\u043c\u0431\u0434 \u2014\u200a\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0431\u0430\u043b\u0430\u043d\u0441 \u043c\u0435\u0436\u0434\u0443 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0442\u043e\u043b\u043a\u043e\u0432\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c. \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043f\u0440\u043e\u0441\u0442:<\/p>\n<p>  <\/p>\n<pre><code>val sum = { x: Int, y: Int -&gt; x + y }   \/\/ type: (Int, Int) -&gt; Int val res = sum(4,7)                      \/\/ res == 11<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0432\u043e\u0442 \u0438 \u0442\u043e\u043b\u043a\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0438\u043b\u0438 \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u0440\u0443\u0433\u043b\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435, \u0435\u0441\u043b\u0438 \u043b\u044f\u043c\u0431\u0434\u0430 \u0438\u0434\u0451\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043b\u0438\u0431\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0430.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u043d\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043d\u043e\u0439 \u043b\u044f\u043c\u0431\u0434\u044b, \u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u044f\u0432\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u043f\u043e\u0434 \u0438\u043c\u0435\u043d\u0435\u043c <code>it<\/code>.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u044d\u0442\u0438\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432 \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b\u043c\u0438 \u044d\u0442\u0438 \u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code>numbers.filter({ x -&gt; x.isPrime() }) numbers.filter { x -&gt; x.isPrime() } numbers.filter { it.isPrime() }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434, \u0432\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u044d\u0442\u0443 \u043a\u0440\u0430\u0441\u043e\u0442\u0443:<\/p>\n<p>  <\/p>\n<pre><code>persons     .filter { it.age &gt;= 18 }     .sortedBy { it.name }     .map { it.email }     .forEach { print(it) }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043b\u044f\u043c\u0431\u0434, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0451\u043d\u043d\u0430\u044f \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f\u043c\u0438, \u0434\u0435\u043b\u0430\u0435\u0442 Kotlin \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f [DSL](C:\\Users\\Desktop\\Cloud Mail.Ru\\Mail \u2014 \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 Kotlin\\\u0432 Kotlin). <a href=\"https:\/\/github.com\/Kotlin\/anko\">Anko<\/a> \u2014 \u043f\u0440\u0438\u043c\u0435\u0440 DSL, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 Android-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code>verticalLayout {     padding = dip(30)     editText {         hint = \u201cName\u201d         textSize = 24f     }     editText {         hint = \u201cPassword\u201d         textSize = 24f     }     button(\u201cLogin\u201d) {         textSize = 26f     } }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"17-podderzhka-ide\">17# \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 IDE<\/h2>\n<p>  <\/p>\n<p>\u0423 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0446\u0435\u043b\u044b\u0439 \u0440\u044f\u0434 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Kotlin, \u043d\u043e \u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>IntelliJ, \u0438\u0434\u0443\u0449\u0438\u0439 \u0432 \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0442\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u043a\u0438 Kotlin<\/strong> \u2014 \u0435\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u043b\u044e\u0434\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u043a\u0430\u043a \u044f\u0437\u044b\u043a, \u0442\u0430\u043a \u0438 IDE.<br \/>  \u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u044d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u0441\u043f\u043b\u044b\u043b\u043e, \u043a\u043e\u0433\u0434\u0430 \u044f \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u0442\u044c Java-\u043a\u043e\u0434 \u0441\u043e Stack Overflow:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/673\/c43\/7d6\/673c437d696649a385ed05d64b487707.png\" alt=\"image\"\/><br \/>  <em>IntelliJ \u0437\u0430\u043c\u0435\u0442\u0438\u0442, \u0447\u0442\u043e \u0432\u044b \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0435 Java-\u043a\u043e\u0434 \u0432 \u0444\u0430\u0439\u043b Kotlin<\/em><\/p>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451, \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0447\u0442\u0435\u043d\u0438\u0435! \u0415\u0441\u043b\u0438 \u043c\u043d\u0435 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0443\u0431\u0435\u0434\u0438\u0442\u044c \u0432\u0430\u0441 \u043d\u0430\u0441\u0447\u0451\u0442 Kotlin, \u0442\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/blog.jetbrains.com\/kotlin\/2017\/05\/kotlin-on-android-now-official\/\">Kotlin on Android. Now official<\/a><\/li>\n<li><a href=\"https:\/\/medium.com\/@octskyward\/why-kotlin-is-my-next-programming-language-c25c001e26e3\">Why Kotlin is my next programming language<\/a><\/li>\n<li><a href=\"https:\/\/agilewombat.com\/2016\/02\/01\/scala-vs-kotlin\/\">Scala vs Kotlin<\/a><\/li>\n<li><a href=\"http:\/\/nilhcem.com\/swift-is-like-kotlin\/\">Swift is like Kotlin<\/a><\/li>\n<li><a href=\"https:\/\/blog.gradle.org\/kotlin-scripting-update\">The Road to Gradle Script Kotlin 1.0<\/a><\/li>\n<li><a href=\"https:\/\/spring.io\/blog\/2017\/01\/04\/introducing-kotlin-support-in-spring-framework-5-0?utm_content=buffer546ec&amp;utm_medium=social&amp;utm_source=twitter.com&amp;utm_campaign=buffer\">Introducing Kotlin support in Spring Framework 5.0<\/a><\/li>\n<li><a href=\"http:\/\/frozenfractal.com\/blog\/2017\/2\/10\/10-cool-things-about-kotlin\/\">10 cool things about Kotlin<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Kotlin\/kotlin-fullstack-sample\">Kotlin full stack application example<\/a><\/li>\n<li><a href=\"https:\/\/hashnode.com\/post\/why-i-abandoned-java-in-favour-of-kotlin-ciuzhmecf09khdc530m1ghu6d\">Why I abandoned Java in favour of Kotlin<\/a><\/li>\n<li><a href=\"https:\/\/medium.com\/@johnnytn.mail\/i-used-kotlin-at-a-hackathon-cd9eab1725f9\">I used Kotlin at Hackathon<\/a><\/li>\n<li><a href=\"https:\/\/fabiomsr.github.io\/from-java-to-kotlin\/\">From Java to Kotlin<\/a><\/li>\n<li><a href=\"https:\/\/kotlinlang.org\/docs\/reference\/idioms.html\">Kotlin Idioms<\/a><\/li>\n<\/ul>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/329294\/\"> https:\/\/habrahabr.ru\/post\/329294\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/4d7\/668\/8cd\/4d76688cd52744f2bd7d1f711f6a3e04.jpg\"\/><\/p>\n<p>  <\/p>\n<p>\u0425\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u043e \u043d\u043e\u0432\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Kotlin, \u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0441\u0432\u043e\u0451\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u0420\u0430\u043d\u044c\u0448\u0435 \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u043b Java, \u043d\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0433\u043e\u0434 \u043f\u0438\u0448\u0443 \u043d\u0430 Kotlin \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e. \u0418 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0441\u0435\u0431\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043b\u0443\u0447\u0448\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0442\u044c Java.<\/p>\n<p>  <\/p>\n<p>Kotlin \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0432 <a href=\"https:\/\/www.jetbrains.com\/\">JetBrains<\/a>, \u0438 \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0442\u0435\u0445 \u0436\u0435 \u043b\u044e\u0434\u0435\u0439 \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 <a href=\"https:\/\/www.jetbrains.com\/products.html?fromMenu#type=ide\">IDE<\/a>, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <strong>IntelliJ<\/strong> \u0438 <strong>ReSharper<\/strong>, \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043f\u043e \u0441\u0430\u043c\u043e\u043c\u0443 \u044f\u0437\u044b\u043a\u0443. \u041e\u043d <strong>\u043f\u0440\u0430\u0433\u043c\u0430\u0442\u0438\u0447\u0435\u043d<\/strong> \u0438 <strong>\u043a\u0440\u0430\u0442\u043e\u043a<\/strong>, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0447\u0435\u043c\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441.<\/p>\n<p>  <\/p>\n<p>\u0425\u043e\u0442\u044f Kotlin \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/kotlinlang.org\/docs\/tutorials\/javascript\/kotlin-to-javascript\/kotlin-to-javascript.html\">JavaScript<\/a> \u0438 \u0441\u043a\u043e\u0440\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 <a href=\"https:\/\/blog.jetbrains.com\/kotlin\/2017\/04\/kotlinnative-tech-preview-kotlin-without-a-vm\/\">\u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434<\/a>, \u044f \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u0443\u044e\u0441\u044c \u043d\u0430 \u0435\u0433\u043e \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435 \u2014 <strong>JVM<\/strong>.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0447\u0438\u043d, \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 Kotlin (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043b\u0443\u0447\u0430\u0435\u043d):<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-286822","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/286822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=286822"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/286822\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=286822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=286822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=286822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}