{"id":93685,"date":"2020-04-12T21:16:09","date_gmt":"2020-04-12T13:16:09","guid":{"rendered":"http:\/\/4563.org\/?p=93685"},"modified":"2020-04-12T21:16:09","modified_gmt":"2020-04-12T13:16:09","slug":"kotlin-%e5%8c%bf%e5%90%8d%e5%87%bd%e6%95%b0%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=93685","title":{"rendered":"Kotlin \u533f\u540d\u51fd\u6570\u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Kotlin \u533f\u540d\u51fd\u6570\u7684\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : TxcA <\/span>  <span><i><\/i> 20<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>    val numbers1 = mutableListOf(0, 1, 2, 3, 4)     val numbers2 = mutableListOf(5, 6, 7, 8, 9)     println(\"numbers : ${numbers1.zip(numbers2) { a, b -&gt; a + b }}\")     println(\"numbers add {} : ${numbers1.zip(numbers2) { a, b -&gt; { a + b } }}\")      \/\/println     \/\/numbers : [5, 7, 9, 11, 13]     \/\/numbers add {} : [() -&gt; kotlin.Int, () -&gt; kotlin.Int, () -&gt; kotlin.Int, () -&gt; kotlin.Int, () -&gt; kotlin.Int] <\/code><\/pre>\n<p>\u4eca\u5929\u65e0\u610f\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u4f7f\u7528 zip \u65f6\u4e00\u76f4\u62a5 null\uff0c\u68c0\u67e5\u597d\u4e45\u540e\u624d\u53d1\u73b0\u591a\u4e86\u4e00\u4e2a\u82b1\u62ec\u53f7\u3002 \u770b\u4e86\u534a\u5929\u59cb\u7ec8\u6ca1\u660e\u767d\uff0c\u4e3a\u4ec0\u4e48\u533f\u540d\u51fd\u6570\u5185\u591a\u52a0\u4e00\u4e2a\u82b1\u62ec\u53f7\u4f1a\u5bfc\u81f4\u8fd4\u56de Unit?<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1162439\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fansangg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u767e\u5ea6\u4e00\u4e0b\u95ed\u5305                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1162440\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : maninfog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u786e\u4fdd 3 \u70b9<br \/>1.lamda \u8868\u8fbe\u5f0f\u4f1a\u9ed8\u8ba4\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u5e76\u63a8\u5bfc\u7c7b\u578b\uff0c\u6bd4\u5982 a+b \u5c31\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u7ed3\u679c\u662f Int\uff0c\u6240\u4ee5 kotlin \u63a8\u5bfc\u51fa\u503c\u662f Int \u7c7b\u578b\u3002<br \/>2.{a +b}\u5c31\u4e0d\u662f Int \u7c7b\u578b\u4e86\uff0c\u5b83\u4e5f\u662f\u4e00\u4e2a lamda \u8868\u8fbe\u5f0f\uff0c\u7c7b\u578b\u5e94\u8be5\u662f\u4e00\u4e2a()-&gt;Int \u7684\u51fd\u6570\u7c7b\u578b\uff0c\u6240\u4ee5\u8fd9\u91cc\u7f16\u8bd1\u5668\u63a8\u5bfc\u51fa\u7c7b\u578b\u4e3a()-&gt;Int \u3002<br \/>3.\u65e2\u7136\u7528\u4e86 kotlin \u5c31\u4e0d\u8981\u7528 java \u7684 lambda \u7684\u5199\u6cd5\u4e86\uff0c\u4e24\u8005\u4e0d\u4e00\u6837                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1162441\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kmyzzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             a+b \u7684\u7c7b\u578b\u662f int \uff1b{ a + b } \u7684\u7c7b\u578b\u662f Unit                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1162442\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : TxcA <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @fansangg \u611f\u8c22\uff0c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1162443\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : TxcA <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @maninfog \u611f\u8c22\uff0c\u5927\u6982\u7406\u89e3\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1162444\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : TxcA <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @kmyzzy \u611f\u8c22\uff0c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Kotlin \u533f\u540d\u51fd\u6570\u7684\u95ee\u9898 \u8cc7\u6df1&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/93685"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=93685"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/93685\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=93685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=93685"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=93685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}