Upgrade to Pro — share decks privately, control downloads, hide ads and more …

はてなブックマークAndroidアプリでのKotlin導入

 はてなブックマークAndroidアプリでのKotlin導入

Takuji Nishibayashi

June 26, 2017
Tweet

More Decks by Takuji Nishibayashi

Other Decks in Technology

Transcript

  1. ͸ͯͳϒοΫϚʔΫ
    AndroidΞϓϦͰͷ
    Kotlinಋೖ
    id:takuji31
    @Kan Java party 2017

    View full-size slide

  2. ஫ҙࣄ߲
    • AndroidΞϓϦ։ൃͷલఏ஌ࣝͱͳΔΑ͏ͳ
    ෦෼ͷղઆ͸͠·ͤΜ
    • ͜ͷεϥΠυʹॻ͔Ε͍ͯΔKotlinͷίʔυ΍
    ࢓༷͸όʔδϣϯ1.1.2࣌఺ͷ΋ͷͰ͢

    View full-size slide

  3. ࣗݾ঺հ
    • ੢ྛ ୓ࢤ (ʹ͠͹΍͠ ͨ͘͡)
    • (hatena|twitter|github) takuji31
    • גࣜձࣾ͸ͯͳ ΞϓϦέʔγϣϯΤϯδχΞ
    • ͸ͯͳϒοΫϚʔΫΞϓϦνʔϜॴଐ

    View full-size slide

  4. ࣗݾ঺հ
    • Android։ൃ 2010೥2݄ʙ
    • Kotlin 2014೥12݄ʙ
    • iOS΍Webͷ։ൃ΋ᅂΉ

    View full-size slide

  5. ׆ಈ
    • Koreference
    • KotlinͰSharedPreferencesͷϞσϧΛ࡞Δ
    ϥΠϒϥϦʔ
    • Kansai.kt ӡӦ

    View full-size slide

  6. ϓϥΠϕʔτ
    • Χϝϥপॅਓ
    • ϚΠϘ΢ϥʔ (AVG175)
    • ࠷ۙ͏͗͞Λࣂ͍࢝Ί·ͨ͠
    • ΞΠίϯ͸͏ͪͷࢠͰ͢

    View full-size slide

  7. Έͳ͞ΜAndroidΞϓϦ
    ։ൃͯ͠·͔͢ʁ

    View full-size slide

  8. Kotlinॻ͍ͯ·͔͢ʁ

    View full-size slide

  9. ࠓ೔͸AndroidΞϓϦ։ൃʹ
    Ͳ͏΍ͬͯKotlinΛಋೖͯ͠
    ͍͔͘Λ࿩͠·͢

    View full-size slide

  10. AGENDA
    • Kotlinʹ͍ͭͯ
    • ͸ͯͳϒοΫϚʔΫʹ͍ͭͯ
    • ͸ͯͳϒοΫϚʔΫΞϓϦνʔϜͷߏ੒
    • Kotlinಋೖ·ͰͷಓͷΓ
    • Kotlinͷಋೖͱͦͷޙ
    • KotlinԽͰى͖Δ໰୊
    • KotlinͷݴޠػೳΛ׆༻͢Δ

    View full-size slide

  11. Kotlin
    ʹ͍ͭͯ

    View full-size slide

  12. JetBrainsࣾ
    (IntelliJ IDEAͷ։ൃݩ) ͕
    ։ൃ͢Δݴޠ

    View full-size slide

  13. Kotlinͷಛ௃
    • Swift like ͳه๏
    • Null safety
    • ܕਪ࿦
    • ϓϩύςΟʔ
    • ϥϜμࣜ

    View full-size slide

  14. Kotlinͷಛ௃
    • ֦ுؔ਺ / ֦ுϓϩύςΟʔ
    • data class / sealed class
    • delegation
    • Coroutine (ex. async/await)

    View full-size slide

  15. ଟ਺ͷϞμϯͳػೳΛ
    උ͍͑ͯΔ

    View full-size slide

  16. Google I/O 2017Ͱ Android
    ΞϓϦͷެࣜ։ൃݴޠʹ

    View full-size slide

  17. ͸ͯͳϒοΫϚʔΫ
    ʹ͍ͭͯ

    View full-size slide

  18. גࣜձࣾ͸ͯͳ͕ӡӦ͢Δ
    ιʔγϟϧϒοΫϚʔΫ
    αʔϏε

    View full-size slide

  19. Web
    Android
    iOS
    ϒϥ΢βʔ֦ு

    View full-size slide

  20. Web͸ScalaͰͷϦχϡʔΞ
    ϧ͕ਐߦத

    View full-size slide

  21. AndroidΞϓϦ͸ઌ೔
    Ϧϊϕʔγϣϯ
    (େن໛ϦϑΝΫλϦϯά)
    ͕׬ྃ㊗

    View full-size slide

  22. http://developer.hatenastaff.com/entry/
    2017/05/26/192200

    View full-size slide

  23. ͸ͯͳϒοΫϚʔΫ
    ΞϓϦνʔϜ
    ʹ͍ͭͯ

    View full-size slide

  24. ϝϯόʔߏ੒
    • σΟϨΫλʔ
    • ϓϥϯφʔ
    • σβΠφʔ
    • Android / iOSΞϓϦ྆ํͷσβΠϯ୲౰

    View full-size slide

  25. ϝϯόʔߏ੒
    • ΤϯδχΞ3໊
    • Swiftίϛολʔ
    • όϦόϦͷAndroidΞϓϦΤϯδχΞ(iOSษڧத)
    • takuji31
    • AndroidΞϓϦͷϝΠϯ୲౰͸takuji31

    View full-size slide

  26. ΤϯδχΞ͸શ෦΍Δ

    View full-size slide

  27. શ෦
    • AndroidΞϓϦ
    • iOSΞϓϦ
    • API
    • اը΍ΞΠσΟΞग़͠ɺνʔϜӡӦʹ΋खΛग़
    ͢

    View full-size slide

  28. ࣾ಺Ͱ࠷΋ΞΫςΟϒͳϞό
    ΠϧΞϓϦ։ൃνʔϜ

    View full-size slide

  29. Kotlin
    ಋೖ·ͰͷಓͷΓ

    View full-size slide

  30. ͸ͯͳͰͷ৽ٕज़
    (ݴޠ΍ϛυϧ΢ΣΞ)
    ಋೖ

    View full-size slide

  31. ಋೖ·Ͱ
    • ΤϯδχΞ͕ىҊ
    • ٕज़ձͰಋೖͷੋඇ͕ٞ࿦͞ΕΔ
    • CTO͕ঝೝ

    View full-size slide

  32. Kotlinͷ৔߹
    • I/O Keynote͕ऴΘͬͨ௚ޙͷேɺKotlinಋೖ
    ىҊ (5/18)
    • ٕज़ձ
    • ঝೝ (5/19)
    • ͜͜·Ͱ͓Αͦ1೔൒

    View full-size slide

  33. Kotlin+͸ͯϒͷ৔߹
    • (ि໌͚ͯ) 22೔͸νʔϜͷD͕ෆࡏͩͬͨͷ
    Ͱ1ճٳΈ
    • 23೔ேʹDͱձ࿩ͯ͠ಋೖܾఆ
    • ଈ೔ಋೖ

    View full-size slide

  34. Kotlin
    ಋೖͱͦͷޙ

    View full-size slide

  35. ͍Α͍ΑKotlinಋೖ

    View full-size slide

  36. खॱ
    • طଘͷΞϓϦέʔγϣϯΛͲ͏KotlinԽ͍ͯ͠
    ͔͘ߟ͑Δ
    • ಋೖ
    • KotlinԽ

    View full-size slide

  37. طଘͷΞϓϦέʔγϣϯΛͲ
    ͏KotlinԽ͍͔ͯ͘͠

    View full-size slide

  38. Ξϓϩʔν
    • શ෦Ұؾʹม׵͢Δ
    • ৽نίʔυ͚ͩKotlinͰॻ͘
    • ৽نίʔυΛKotlinͰॻ͖ͭͭɺؔ࿈͢Δ෦෼
    Λม׵͢Δ

    View full-size slide

  39. શ෦Ұؾʹஔ͖׵͑Δ

    View full-size slide

  40. શ෦Ұؾʹஔ͖׵͑Δ
    • ·ͱΊͯKotlinϓϥάΠϯͷࣗಈม׵Λߦ͏
    • ৽نίʔυ͸΋ͪΖΜKotlin

    View full-size slide

  41. ϝϦοτ
    • શ෦ஔ͖׵ΘͬͯεοΩϦ͢Δ
    • Javaͱͷ૬ޓӡ༻Λߟ͑Δඞཁ͕ͳ͘ͳΔ
    • ؾ͍͍࣋ͪ

    View full-size slide

  42. σϝϦοτ
    • diff͕ഁ໓͢Δ
    • Ұؾʹม׵ࣗಈม׵ͷखͷಧ͔ͳ͍ͱ͜Ζ
    ΛखಈͰमਖ਼޻਺∞
    • ஔ͖׵Θͬͨͷ͸จ๏͚ͩͰɺKotlinΒ͍͠ॻ
    ͖ํ͸Կ΋Ͱ͖͍ͯͳ͍

    View full-size slide

  43. ࿘ອͰ͢Ͷ

    View full-size slide

  44. ৽نίʔυ͚ͩKotlinͰॻ͘

    View full-size slide

  45. ৽نίʔυ͚ͩKotlinͰॻ͘
    • ৽͍͠ϑΝΠϧ͚ͩKotlinʹ͢Δ
    • طଘͷJavaίʔυ͸ϊʔλον
    • طଘ෦෼ͷमਖ਼͸ͦͷ··JavaͰॻ͘

    View full-size slide

  46. ϝϦοτ
    • ม׵ʹΑΔdiff͕ͳ͍
    • KotlinͷֶशϖʔεΛίϯτϩʔϧ͠΍͍͢
    • ͱΓ͋͑ͣ෼͔Βͳ͔ͬͨΒJavaͰॻ͍ͨΒ
    ͍͍ͱ͍͏͜ͱʹͰ͖Δ
    • ม׵޻਺θϩ

    View full-size slide

  47. σϝϦοτ
    • ಋೖײബ͍
    • Javaͱͷ૬ޓӡ༻Λҙࣝͨ͠ίʔυΛॻ͔ͳ͚Ε͹ͳΒͳ͍
    • JavaͱKotlinͰ಄ͷίϯςΩετεΠον͕ൃੜ͢ΔͷͰ͋·Γੜ
    ࢈ੑ͸ग़ͳ͍ʢݸਓͷײ૝Ͱ͢ʣ
    • ݁ہJava͹͔ͬΓॻ͔ΕͨΓ͢Δ͔΋͠Εͳ͍
    • Ϟμϯͳػೳ͕࢖͍ͮΒ͔ͬͨΓ͢Δʢ֦ுؔ਺ͱ͔ʣ
    • ؾ࣋ͪΑ͘ͳ͍

    View full-size slide

  48. ҆શࡦͬͯ
    ײ͡Ͱ͢Ͷ

    View full-size slide

  49. ৽نίʔυΛKotlinͰॻ͖ͭ
    ͭɺؔ࿈͢Δ෦෼Λม׵͢Δ

    View full-size slide

  50. ৽نKotlinʴม׵
    • ৽نίʔυ͸KotlinͰॻ͘
    • ͦͷίʔυΛݺͼग़͢ઌ΍ɺͦ͜Ͱ࢖͏ίʔ
    υΛKotlinʹม׵͢Δ
    • طଘͷΫϥεʹϝιουΛ௥Ճ͢ΔΑ͏ͳ࣌
    ʹ΋Kotlinʹม׵͢Δ

    View full-size slide

  51. ϝϦοτ
    • ൺֱతߴ͍ಋೖײ
    • ͻͨ͢ΒKotlinΛॻ͚Δ
    • Javaͱͷ૬ޓӡ༻Λ΄ͱΜͲҙࣝ͠ͳͯ͘Α
    ͘ͳΔ
    • ؾ͍͍࣋ͪ

    View full-size slide

  52. σϝϦοτ
    • diff͸·͊·͍͊͢͜͝ͱʹͳΔ
    • ͋ͳͨͱKotlinࠓֶ͙͢शɺͱ͍͏ײ͡ʹͳΔ
    • ม׵ίετ͸͋Δ
    • Ͳ͜·Ͱม׵͢Δ͔ͷઢҾ͖͕೉͍͠

    View full-size slide

  53. όϥϯε͕
    ྑͦ͞͏Ͱ͢Ͷ

    View full-size slide

  54. Ξϓϩʔν
    • શ෦Ұؾʹม׵͢Δ
    • ৽نίʔυ͚ͩKotlinͰॻ͘
    • ৽نίʔυΛKotlinͰॻ͖ͭͭɺؔ࿈͢Δ෦෼
    ΛKotlinʹม׵ ࠾༻

    View full-size slide

  55. Gradleͷઃఆ
    Λ௥Ճ

    View full-size slide

  56. Tools Kotlin Configure
    Kotlin in Project

    View full-size slide

  57. ͋ͱ͸
    Android Studioʹ೚ͤͯ
    ͓͚͹ऴΘΔ

    View full-size slide

  58. aptΛkaptʹ
    ஔ͖׵͑Δ

    View full-size slide

  59. Kotlin޲͚ͷ
    ϥΠϒϥϦʔಋೖ

    View full-size slide

  60. ϥΠϒϥϦʔΛಋೖ͢Δ͔
    • KotlinͷݴޠػೳΛ࠷େݶ׆༻͢ΔͨΊʹ͸ඞ

    • KotlinΦϯϦʔͷϥΠϒϥϦʔ͸ΞΫςΟϒͳ
    ΋ͷ͕গͳ͍ͷͰ͸ʁ
    • KotlinͷݴޠόʔδϣϯͷมߋʹϥΠϒϥϦʔ
    ͕͍͍͚ͭͯΔ͔ʁ

    View full-size slide

  61. ಋೖͷࢦ਑
    • طଘϥΠϒϥϦʔͷ֦ு͸ੵۃతʹಋೖͯ͠
    ͍͘
    • KotlinΦϯϦʔͷϥΠϒϥϦʔ͸৻ॏʹબͿ

    View full-size slide

  62. KotlinԽʹ౰ͨͬͯಋೖͨ͠ϥΠϒ
    ϥϦʔୈ1஄
    • RxKotlin
    • RxJavaͷKotlin֦ு
    • ศརͳ֦ுؔ਺܈

    View full-size slide

  63. KotlinԽʹ౰ͨͬͯಋೖͨ͠ϥΠϒ
    ϥϦʔୈ1஄
    • PaperParcel
    • Java੡ͷParcelableࣗಈੜ੒ϥΠϒϥϦʔ
    • ͜Ε·Ͱ͸IDEͷࣗಈੜ੒ͰͳΜͱ͔͍ͯͨ͠
    • ͔͔ͤͬͩ͘Βboilerplate codeݮΒ͍ͨ͠ͷͰಋೖ
    • Kotlinͷdata classαϙʔτ
    • ଞͷParcelableܥϥΠϒϥϦʔΑΓKotlinͱͷ૬ੑ͕Α͔ͬͨ

    View full-size slide

  64. KotlinԽʹ౰ͨͬͯಋೖͨ͠ϥΠϒ
    ϥϦʔୈ1஄
    • Koreference
    • ੿࡞
    • SharedPreferencesΛ͍͍ײ͡ʹModelͬΆ͘ѻ͏ϥΠϒϥϦʔ
    • ϓϩύςΟʔΛఆٛ͢Δ͚ͩͰSharedPreferencesͷ஋Λૢ࡞Ͱ͖Δ
    • RxJava2ʹΑΔมߋ஋؂ࢹαϙʔτ
    • ͱʹ͔͘खͰSharedPreferencesͷॲཧॻ͖ͨ͘ͳ͍ͷͰಋೖ
    • υοάϑʔσΟϯά΋݉Ͷͯ

    View full-size slide

  65. ϥΠηϯεදه

    View full-size slide

  66. Kotlin͸Apache2ϥΠηϯ
    ε

    View full-size slide

  67. ඪ४ϥΠϒϥϦʔ͕ґଘͰ
    ೖΔͷͰϥΠηϯε΋දه
    ͠·͠ΐ͏

    View full-size slide

  68. ·ͣ͸ࢼͯ͠Έͨ

    View full-size slide

  69. ৽͍͠ActivityΛKotlinͰ

    View full-size slide

  70. ৽͍͠ActivityΛKotlinͰ
    • ৽نϑΝΠϧϝχϡʔͷKotlin ActivityΛબ୒
    • Ұ୴ଞͷΫϥε͸ม׵ͤͣʹActivity͚ͩ
    KotlinͰॻ͘
    • Pull Request -> merge

    View full-size slide

  71. طଘͷRepositoryʹ
    ϝιουΛ௥Ճ͢Δ

    View full-size slide

  72. طଘͷRepositoryʹϝιουΛ
    ௥Ճ͢Δ
    • ΫϥεϑΝΠϧΛCode Convert Java file to Kotlin fileͰKotlinʹ
    ม׵
    • KotlinΒ͘͠ॻ͚Δͱ͜Ζ͸ॻ͖׵͑Δ
    • ֦ுؔ਺
    • ϓϩύςΟʔ
    • ϥϜμࣜ
    • Repository͔Βฦ͢model͸Kotlinͷdata class

    View full-size slide

  73. طଘͷRepositoryʹϝιουΛ
    ௥Ճ͢Δ
    • ϩδοΫͷ࣮૷
    • Pull Request merge

    View full-size slide

  74. Kotlin
    ಋೖͰى͖Δ໰୊

    View full-size slide

  75. diffഁ໓໰୊

    View full-size slide

  76. ΫϥεAΛJava Kotlin ͢Δ
    = A.java Λফͯ͠ A.ktΛ௥Ճ

    View full-size slide

  77. ίʔυͷमਖ਼ΛೖΕͨΒɺ
    ߋʹͦͷத͔ΒมߋΛݟ͚ͭ
    ͳ͚Ε͹ͳΒͳ͍ɻ

    View full-size slide

  78. ม׵͚ͩઌʹ΍͓ͬͯ͘
    (Pull RequestΛ෼͚Δ)

    View full-size slide

  79. gitྺ࢙ফ໓໰୊

    View full-size slide

  80. ม׵͢Δ͜ͱͰผϑΝΠϧʹ
    ͳΔͷͰɺgitͷཤྺ͕௥͑ͳ
    ͘ͳΔ

    View full-size slide

  81. ࣗಈม׵͕gitͰrenameѻ͍
    ʹͳΕ͹ϥοΩʔ͕ͩɺͦ͏
    ͍͏ϑΝΠϧ͸ن໛͕খ͍͞
    ͷͰࠔΒͳ͍͜ͱ͕ଟ͍

    View full-size slide

  82. ࠷ѱͷղܾํ๏

    View full-size slide

  83. .ktʹϦωʔϜͯ͠ίϛοτ
    .javaʹ໭ͯ͠ม׵ͯ͠
    ίϛοτ

    View full-size slide

  84. ͜ͷํ๏Ͱ git log --follow
    Ͱ௥͑ΔΑ͏ʹͳΔ

    View full-size slide

  85. (࢖ͬͯͳ͍)

    View full-size slide

  86. ϨϏϡʔίετ
    ߴ͗͢໰୊

    View full-size slide

  87. ίʔυϨϏϡϫʔ͕Kotlinʹ
    ׳Εͯͳ͗ͯ͢͞ϨϏϡʔਫ਼
    ౓͕Լ͕ͬͨΓɺεϐʔυ͕
    མͪΔ

    View full-size slide

  88. ׳Εͷ໰୊

    View full-size slide

  89. ϒοΫϚʔΫΞϓϦνʔϜ
    Ͱ͸ϖΞͰίʔυϨϏϡʔ

    View full-size slide

  90. ձ࿩Ͱٙ໰Λղܾ

    View full-size slide

  91. Kotlinॻ͚ͳ͍໰୊

    View full-size slide

  92. ͍͖ͳΓ৽͍͠ݴޠॻ͚ͳ͍
    (౰ͨΓલ)

    View full-size slide

  93. ॻ͚Δਓ͕νʔϜʹ1,2ਓ͔͠
    ͍ͳ͍…ʁ

    View full-size slide

  94. ಛʹJavaҎ֎ॻ͍ͨ͜ͱ͕
    ͳ͍ɺͱ͍͏ਓ

    View full-size slide

  95. ≒ Ϟμϯͳݴޠͷॻ͖ํ͕෼
    ͔Βͳ͍

    View full-size slide

  96. ॻ͚Δਓͱ
    ϖΞϓϩɺϖΞϨϏϡʔ
    ͠·͠ΐ͏

    View full-size slide

  97. ϒοΫϚʔΫΞϓϦνʔϜ͸
    ͳΜͱͳ͘ॻ͚Δਓ͕
    ἧ͍ͬͯͨ☺

    View full-size slide

  98. ୭΋ॻ͚Δਓ͕͍ͳ͍ͳΒ
    ·ͣಋೖલʹֶशͯ͘͠Εʂ

    View full-size slide

  99. kotlinlang.org/docs/
    reference/

    View full-size slide

  100. try.kotlinlang.org

    View full-size slide

  101. Kotlin
    ͷݴޠػೳΛ
    ׆༻͢Δ

    View full-size slide

  102. Πϯελϯεͷঢ়ଶΛ
    ද͢࢓૊Έ

    View full-size slide

  103. getter
    (+setter)
    (+ backing field)

    View full-size slide

  104. Property
    class User(id: Long, name: String) {

    val id: Long

    var name: String

    var registered: Boolean = false


    init {

    this.id = id

    this.name = name

    }


    }


    View full-size slide

  105. Property
    class User(id: Long, name: String) {

    val id: Long

    var name: String

    var registered: Boolean = false


    init {

    this.id = id

    this.name = name

    }


    }


    ಡΈऔΓઐ༻

    View full-size slide

  106. Property
    class User(id: Long, name: String) {

    val id: Long

    var name: String

    var registered: Boolean = false


    init {

    this.id = id

    this.name = name

    }


    }


    ಡΈऔΓઐ༻
    ಡΈॻ͖Մ

    View full-size slide

  107. Property
    class User(id: Long, name: String) {

    val id: Long

    var name: String

    var registered: Boolean = false


    init {

    this.id = id

    this.name = name

    }


    }


    ಡΈऔΓઐ༻
    ಡΈॻ͖Մ
    ܕ

    View full-size slide

  108. Property
    class User(id: Long, name: String) {

    val id: Long

    var name: String

    var registered: Boolean = false


    init {

    this.id = id

    this.name = name

    }


    }


    ಡΈऔΓઐ༻
    ಡΈॻ͖Մ
    ܕ
    ॳظ஋

    View full-size slide

  109. Property
    class User(id: Long, name: String) {

    val id: Long

    var name: String

    var registered: Boolean = false


    init {

    this.id = id

    this.name = name

    }


    }


    ಡΈऔΓઐ༻
    ಡΈॻ͖Մ
    ܕ
    ॳظ஋
    JOJUϒϩοΫͰ
    ॳظԽ

    View full-size slide

  110. ͜͏ஔ͖׵͑ΒΕ·͢
    class User(val id: Long, var name: String) {

    var registered: Boolean = false

    }


    View full-size slide

  111. ͜͏ஔ͖׵͑ΒΕ·͢
    class User(val id: Long, var name: String) {

    var registered: Boolean = false

    }


    ίϯετϥΫλʔ಺Ͱ
    ϓϩύςΟʔఆٛ͢Δͱɺࣗಈతʹ୅ೖ͞ΕΔ

    View full-size slide

  112. registered΋஋Λड͚औΕΔΑ͏ʹ
    class User(

    val id: Long,

    var name: String,

    var registered: Boolean = false

    )


    View full-size slide

  113. registered΋஋Λड͚औΕΔΑ͏ʹ
    class User(

    val id: Long,

    var name: String,

    var registered: Boolean = false

    )


    SFHJTUFSFEΛ౉͞ͳ͔ͬͨΒGBMTF͕୅ೖ͞ΕΔ

    View full-size slide

  114. ԿΒ͔ͷσʔλʔΛอ࣋͢Δ
    ͨΊͷΫϥε

    View full-size slide

  115. Model΍DTOΛ࡞ΔͨΊͷ
    ศརػೳຬࡌ

    View full-size slide

  116. ex.) طଘͷmodelΛKotlinʹ
    ม׵͍ͨ͠

    View full-size slide

  117. ม׵͸Convert Java file to
    Kotlin fileͰ

    View full-size slide

  118. ୯७ͳม׵͚ͩͰΑ͍ͷ͔ʁ

    View full-size slide

  119. ୯७ͳม׵͚ͩͰΑ͍ͷ͔ʁ
    • Immutableʹ͍ͨ͠
    • equals/hashCode/toStringͷ࣮૷

    View full-size slide

  120. શͯͷϓϩύςΟʔΛvalͰ
    ఆٛ + constructorͰ୅ೖ

    View full-size slide

  121. એݴ
    class User(

    val id: Long,

    val name: String,

    val registered: Boolean

    )

    View full-size slide

  122. ࢖͏
    fun main(args: Array) {

    val unregisteredUser = User(
    id = 114514L,
    name = "takuji31",
    registered = false
    )

    val user = register(unregisteredUser)

    print(user)

    }


    fun register(user: User): User {

    // do something

    return User(user.id, user.name, true)

    }

    View full-size slide

  123. ίϐʔΛ΋ͬͱ͍͍ײ͡ʹ͠
    ͍ͨ

    View full-size slide

  124. data classΛ࢖͏

    View full-size slide

  125. એݴ
    data class User(

    val id: Long,

    val name: String,

    val registered: Boolean = false

    )

    View full-size slide

  126. એݴ
    data class User(

    val id: Long,

    val name: String,

    val registered: Boolean = false

    )

    ಄ʹEBUB
    Λ͚ͭΔ

    View full-size slide

  127. એݴ
    data class User(

    val id: Long,

    val name: String,

    val registered: Boolean = false

    )

    ಄ʹEBUB
    Λ͚ͭΔ
    શͯͷϓϩύςΟʔΛ
    DPOTUSVDUPSͰఆٛ

    View full-size slide

  128. ࢖͏
    fun register(user: User): User {

    // do something

    return user.copy(registered = true)

    }

    View full-size slide

  129. ࢖͏
    fun register(user: User): User {

    // do something

    return user.copy(registered = true)

    }

    DPQZϝιουͷҾ਺ʹ
    มߋ͍ͨ͠஋͚ͩΛ౉͢ͱ
    ίϐʔ͞ΕΔ

    View full-size slide

  130. equals/hashCode/toString
    ͷ࣮૷

    View full-size slide

  131. data classΛ࢖͏ͱࣗಈੜ੒
    ͞ΕΔ

    View full-size slide

  132. ͸ͯͳϒοΫϚʔΫAndroid
    ΞϓϦͰ͸
    modelΛdata class΁
    ੵۃతʹஔ͖׵͍͑ͯ·͢

    View full-size slide

  133. ֦ுؔ਺/֦ுϓϩύςΟʔ

    View full-size slide

  134. طଘͷΫϥεʹ
    ؔ਺΍ϓϩύςΟʔΛੜ΍͢
    (Α͏ʹݟͤΔ)࢓૊Έ

    View full-size slide

  135. ϑϨʔϜϫʔΫ΍ϥΠϒϥϦʔ
    ͷΫϥεΛ֦ு͍ͯ͘͠ͱΑ
    ͍

    View full-size slide

  136. FragmentΛ֦ுϓϩύςΟʔͰ
    ֦ு͢Δ
    val Fragment.baseActivity: BaseActivity?

    get() = activity as BaseActivity?

    val Fragment.actionBar: ActionBar?

    get() = baseActivity?.supportActionBar

    View full-size slide

  137. FragmentΛ֦ுϓϩύςΟʔͰ
    ֦ு͢Δ
    val Fragment.baseActivity: BaseActivity?

    get() = activity as BaseActivity?

    val Fragment.actionBar: ActionBar?

    get() = baseActivity?.supportActionBar

    ֦ு͍ͨ͠ܕ
    Λॻ͘

    View full-size slide

  138. FragmentΛ֦ுϓϩύςΟʔͰ
    ֦ு͢Δ
    val Fragment.baseActivity: BaseActivity?

    get() = activity as BaseActivity?

    val Fragment.actionBar: ActionBar?

    get() = baseActivity?.supportActionBar

    ֦ு͍ͨ͠ܕ
    Λॻ͘
    ͦͷଞ͸௨ৗͷ
    ϓϩύςΟʔͱಉ͡

    View full-size slide

  139. RealmͷProviderΛ֦ுؔ਺Ͱ
    ֦ு͢Δ
    fun Provider.getAutoCloseObservable():
    Observable {

    val realm = get()

    realm.use {

    return Observable.create { emitter ->

    val instance = get()

    emitter.setCancellable {

    instance.close()

    }

    emitter.onNext(instance)

    }

    }

    }

    View full-size slide

  140. RealmͷProviderΛ֦ுؔ਺Ͱ
    ֦ு͢Δ
    fun Provider.getAutoCloseObservable():
    Observable {

    val realm = get()

    realm.use {

    return Observable.create { emitter ->

    val instance = get()

    emitter.setCancellable {

    instance.close()

    }

    emitter.onNext(instance)

    }

    }

    }

    ֦ு͍ͨ͠ܕ
    Λॻ͘

    View full-size slide

  141. RealmͷProviderΛ֦ுؔ਺Ͱ
    ֦ு͢Δ
    fun Provider.getAutoCloseObservable():
    Observable {

    val realm = get()

    realm.use {

    return Observable.create { emitter ->

    val instance = get()

    emitter.setCancellable {

    instance.close()

    }

    emitter.onNext(instance)

    }

    }

    }

    ֦ு͍ͨ͠ܕ
    Λॻ͘
    (FOFSJDTͷ
    ܕύϥϝʔλʔ΋ࢦఆՄ

    ϓϩύςΟʔ΋ಉ༷

    View full-size slide

  142. RealmͷProviderΛ֦ுؔ਺Ͱ
    ֦ு͢Δ
    fun Provider.getAutoCloseObservable():
    Observable {

    val realm = get()

    realm.use {

    return Observable.create { emitter ->

    val instance = get()

    emitter.setCancellable {

    instance.close()

    }

    emitter.onNext(instance)

    }

    }

    }

    ֦ு͍ͨ͠ܕ
    Λॻ͘
    ͦͷଞ͸௨ৗͷ
    ؔ਺ͱಉ͡
    (FOFSJDTͷ
    ܕύϥϝʔλʔ΋ࢦఆՄ

    ϓϩύςΟʔ΋ಉ༷

    View full-size slide

  143. ࣮ࡍʹ֦ு͞ΕΔ
    ͷͰ͸ͳ͘ɺ
    ࣮ମ͸staticͳ
    ϝιουݺͼग़͠

    View full-size slide

  144. = ֦ுϓϩύςΟʔ͸ϑΟʔ
    ϧυΛ࣋ͯͳ͍

    View full-size slide

  145. ఘΊͯଞͷΞϓϩʔνΛ
    ߟ͑·͠ΐ͏

    View full-size slide

  146. ֦ு͗͢͠Δͱ
    Θ͚͕Θ͔Βͳ͘ͳΔ

    View full-size slide

  147. ΍Γա͗஫ҙ

    View full-size slide

  148. Delegated
    property

    View full-size slide

  149. ҕৡϓϩύςΟʔ

    View full-size slide

  150. ॲཧΛҕৡ͢Δ
    ϓϩύςΟʔΛ
    ࡞Δ͜ͱ͕Ͱ͖Δ

    View full-size slide

  151. σϑΥϧτͷ
    Delegated property(Ұ෦)
    • Delegates.notNull
    • not-null͕ͩॳظԽ࣌ʹॳظԽͰ͖ͳ͍ϓϩύςΟʔ
    • nullͷ··ΞΫηεͨ͠Βྫ֎
    • lazy
    • ஗ԆॳظԽ
    • ࠷ॳͷΞΫηε࣌ʹҾ਺Ͱ౉ͨ͠ϒϩοΫͷ໭Γ஋Λฦͯ͠
    Ωϟογϡ͢Δ

    View full-size slide

  152. ଟ෼͕࣌ؒ଍Γͳ͍ͷͰ

    View full-size slide

  153. see.
    github.com/takuji31/
    Koreference

    View full-size slide

  154. Enjoy Kotlin Life

    View full-size slide