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

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

E28404a128b6014e6f499d2a967c72a0?s=128

Takuji Nishibayashi

June 26, 2017
Tweet

Transcript

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

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

  3. ࣗݾ঺հ • ੢ྛ ୓ࢤ (ʹ͠͹΍͠ ͨ͘͡) • (hatena|twitter|github) takuji31 •

    גࣜձࣾ͸ͯͳ ΞϓϦέʔγϣϯΤϯδχΞ • ͸ͯͳϒοΫϚʔΫΞϓϦνʔϜॴଐ 
  4. ࣗݾ঺հ • Android։ൃ 2010೥2݄ʙ • Kotlin 2014೥12݄ʙ • iOS΍Webͷ։ൃ΋ᅂΉ 

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

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

    
  7. ͱ͜ΖͰ 

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

  9. Kotlinॻ͍ͯ·͔͢ʁ 

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

  11. AGENDA • Kotlinʹ͍ͭͯ • ͸ͯͳϒοΫϚʔΫʹ͍ͭͯ • ͸ͯͳϒοΫϚʔΫΞϓϦνʔϜͷߏ੒ • Kotlinಋೖ·ͰͷಓͷΓ •

    Kotlinͷಋೖͱͦͷޙ • KotlinԽͰى͖Δ໰୊ • KotlinͷݴޠػೳΛ׆༻͢Δ 
  12. Kotlin ʹ͍ͭͯ 

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

  14. Kotlinͷಛ௃ • Swift like ͳه๏ • Null safety • ܕਪ࿦

    • ϓϩύςΟʔ • ϥϜμࣜ 
  15. Kotlinͷಛ௃ • ֦ுؔ਺ / ֦ுϓϩύςΟʔ • data class / sealed

    class • delegation • Coroutine (ex. async/await) 
  16. ଟ਺ͷϞμϯͳػೳΛ උ͍͑ͯΔ 

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

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

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

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

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

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

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

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

  25. ϝϯόʔߏ੒ • σΟϨΫλʔ • ϓϥϯφʔ • σβΠφʔ • Android /

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

    AndroidΞϓϦͷϝΠϯ୲౰͸takuji31 
  27. ΤϯδχΞ͸શ෦΍Δ 

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

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

  30. Kotlin ಋೖ·ͰͷಓͷΓ 

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

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

  33. Kotlinͷ৔߹ • I/O Keynote͕ऴΘͬͨ௚ޙͷேɺKotlinಋೖ ىҊ (5/18) • ٕज़ձ • ঝೝ

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

  35. Kotlin ಋೖͱͦͷޙ 

  36. ͍Α͍ΑKotlinಋೖ 

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

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

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

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

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

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

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

  44. ࿘ອͰ͢Ͷ 

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

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

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

    
  48. σϝϦοτ • ಋೖײബ͍ • Javaͱͷ૬ޓӡ༻Λҙࣝͨ͠ίʔυΛॻ͔ͳ͚Ε͹ͳΒͳ͍ • JavaͱKotlinͰ಄ͷίϯςΩετεΠον͕ൃੜ͢ΔͷͰ͋·Γੜ ࢈ੑ͸ग़ͳ͍ʢݸਓͷײ૝Ͱ͢ʣ • ݁ہJava͹͔ͬΓॻ͔ΕͨΓ͢Δ͔΋͠Εͳ͍

    • Ϟμϯͳػೳ͕࢖͍ͮΒ͔ͬͨΓ͢Δʢ֦ுؔ਺ͱ͔ʣ • ؾ࣋ͪΑ͘ͳ͍ 
  49. ҆શࡦͬͯ ײ͡Ͱ͢Ͷ 

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

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

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

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

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

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

  56. ಋೖ 

  57. Gradleͷઃఆ Λ௥Ճ 

  58. Tools Kotlin Configure Kotlin in Project 

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

  60. aptΛkaptʹ ஔ͖׵͑Δ 

  61. 

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

  63. ϥΠϒϥϦʔΛಋೖ͢Δ͔ • KotlinͷݴޠػೳΛ࠷େݶ׆༻͢ΔͨΊʹ͸ඞ ཁ • KotlinΦϯϦʔͷϥΠϒϥϦʔ͸ΞΫςΟϒͳ ΋ͷ͕গͳ͍ͷͰ͸ʁ • KotlinͷݴޠόʔδϣϯͷมߋʹϥΠϒϥϦʔ ͕͍͍͚ͭͯΔ͔ʁ

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

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

  66. KotlinԽʹ౰ͨͬͯಋೖͨ͠ϥΠϒ ϥϦʔୈ1஄ • PaperParcel • Java੡ͷParcelableࣗಈੜ੒ϥΠϒϥϦʔ • ͜Ε·Ͱ͸IDEͷࣗಈੜ੒ͰͳΜͱ͔͍ͯͨ͠ • ͔͔ͤͬͩ͘Βboilerplate

    codeݮΒ͍ͨ͠ͷͰಋೖ • Kotlinͷdata classαϙʔτ • ଞͷParcelableܥϥΠϒϥϦʔΑΓKotlinͱͷ૬ੑ͕Α͔ͬͨ 
  67. KotlinԽʹ౰ͨͬͯಋೖͨ͠ϥΠϒ ϥϦʔୈ1஄ • Koreference • ੿࡞ • SharedPreferencesΛ͍͍ײ͡ʹModelͬΆ͘ѻ͏ϥΠϒϥϦʔ • ϓϩύςΟʔΛఆٛ͢Δ͚ͩͰSharedPreferencesͷ஋Λૢ࡞Ͱ͖Δ

    • RxJava2ʹΑΔมߋ஋؂ࢹαϙʔτ • ͱʹ͔͘खͰSharedPreferencesͷॲཧॻ͖ͨ͘ͳ͍ͷͰಋೖ • υοάϑʔσΟϯά΋݉Ͷͯ 
  68. ϥΠηϯεදه 

  69. Kotlin͸Apache2ϥΠηϯ ε 

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

  71. 

  72. 

  73. KotlinԽ 

  74. ·ͣ͸ࢼͯ͠Έͨ 

  75. ৽͍͠ActivityΛKotlinͰ 

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

    -> merge 
  77. طଘͷRepositoryʹ ϝιουΛ௥Ճ͢Δ 

  78. طଘͷRepositoryʹϝιουΛ ௥Ճ͢Δ • ΫϥεϑΝΠϧΛCode Convert Java file to Kotlin fileͰKotlinʹ

    ม׵ • KotlinΒ͘͠ॻ͚Δͱ͜Ζ͸ॻ͖׵͑Δ • ֦ுؔ਺ • ϓϩύςΟʔ • ϥϜμࣜ • Repository͔Βฦ͢model͸Kotlinͷdata class 
  79. طଘͷRepositoryʹϝιουΛ ௥Ճ͢Δ • ϩδοΫͷ࣮૷ • Pull Request merge 

  80. Kotlin ಋೖͰى͖Δ໰୊ 

  81. diffഁ໓໰୊ 

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

  83. 2ഒͷdiff 

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

  85. 

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

  87. gitྺ࢙ফ໓໰୊ 

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

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

  90. ࠷ѱͷղܾํ๏ 

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

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

  93. (࢖ͬͯͳ͍) 

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

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

  96. ׳Εͷ໰୊ 

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

  98. ձ࿩Ͱٙ໰Λղܾ 

  99. 

  100. Kotlinॻ͚ͳ͍໰୊ 

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

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

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

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

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

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

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

  108. kotlinlang.org/docs/ reference/ 

  109. try.kotlinlang.org 

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

  111. Property 

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

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

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


    var name: String
 var registered: Boolean = false
 
 init {
 this.id = id
 this.name = name
 }
 
 }
 
  115. Property class User(id: Long, name: String) {
 val id: Long


    var name: String
 var registered: Boolean = false
 
 init {
 this.id = id
 this.name = name
 }
 
 }
  ಡΈऔΓઐ༻
  116. Property class User(id: Long, name: String) {
 val id: Long


    var name: String
 var registered: Boolean = false
 
 init {
 this.id = id
 this.name = name
 }
 
 }
  ಡΈऔΓઐ༻ ಡΈॻ͖Մ
  117. Property class User(id: Long, name: String) {
 val id: Long


    var name: String
 var registered: Boolean = false
 
 init {
 this.id = id
 this.name = name
 }
 
 }
  ಡΈऔΓઐ༻ ಡΈॻ͖Մ ܕ
  118. Property class User(id: Long, name: String) {
 val id: Long


    var name: String
 var registered: Boolean = false
 
 init {
 this.id = id
 this.name = name
 }
 
 }
  ಡΈऔΓઐ༻ ಡΈॻ͖Մ ܕ ॳظ஋
  119. 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ϒϩοΫͰ ॳظԽ
  120. ͜͏ஔ͖׵͑ΒΕ·͢ class User(val id: Long, var name: String) {
 var

    registered: Boolean = false
 }
 
  121. ͜͏ஔ͖׵͑ΒΕ·͢ class User(val id: Long, var name: String) {
 var

    registered: Boolean = false
 }
  ίϯετϥΫλʔ಺Ͱ ϓϩύςΟʔఆٛ͢Δͱɺࣗಈతʹ୅ೖ͞ΕΔ
  122. registered΋஋Λड͚औΕΔΑ͏ʹ class User(
 val id: Long,
 var name: String,
 var

    registered: Boolean = false
 )
 
  123. registered΋஋Λड͚औΕΔΑ͏ʹ class User(
 val id: Long,
 var name: String,
 var

    registered: Boolean = false
 )
  SFHJTUFSFEΛ౉͞ͳ͔ͬͨΒGBMTF͕୅ೖ͞ΕΔ
  124. data class 

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

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

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

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

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

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

  131. Immutableʹ 

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

  133. એݴ class User(
 val id: Long,
 val name: String,
 val

    registered: Boolean
 ) 
  134. ࢖͏ fun main(args: Array<String>) {
 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)
 } 
  135. ίϐʔΛ΋ͬͱ͍͍ײ͡ʹ͠ ͍ͨ 

  136. data classΛ࢖͏ 

  137. એݴ data class User(
 val id: Long,
 val name: String,


    val registered: Boolean = false
 ) 
  138. એݴ data class User(
 val id: Long,
 val name: String,


    val registered: Boolean = false
 )  ಄ʹEBUB Λ͚ͭΔ
  139. એݴ data class User(
 val id: Long,
 val name: String,


    val registered: Boolean = false
 )  ಄ʹEBUB Λ͚ͭΔ શͯͷϓϩύςΟʔΛ DPOTUSVDUPSͰఆٛ
  140. ࢖͏ fun register(user: User): User {
 // do something
 return

    user.copy(registered = true)
 } 
  141. ࢖͏ fun register(user: User): User {
 // do something
 return

    user.copy(registered = true)
 }  DPQZϝιουͷҾ਺ʹ มߋ͍ͨ͠஋͚ͩΛ౉͢ͱ ίϐʔ͞ΕΔ
  142. equals/hashCode/toString ͷ࣮૷ 

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

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

  145. Extension 

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

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

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

  149. FragmentΛ֦ுϓϩύςΟʔͰ ֦ு͢Δ val Fragment.baseActivity: BaseActivity?
 get() = activity as BaseActivity?


    val Fragment.actionBar: ActionBar?
 get() = baseActivity?.supportActionBar 
  150. FragmentΛ֦ுϓϩύςΟʔͰ ֦ு͢Δ val Fragment.baseActivity: BaseActivity?
 get() = activity as BaseActivity?


    val Fragment.actionBar: ActionBar?
 get() = baseActivity?.supportActionBar  ֦ு͍ͨ͠ܕ Λॻ͘
  151. FragmentΛ֦ுϓϩύςΟʔͰ ֦ு͢Δ val Fragment.baseActivity: BaseActivity?
 get() = activity as BaseActivity?


    val Fragment.actionBar: ActionBar?
 get() = baseActivity?.supportActionBar  ֦ு͍ͨ͠ܕ Λॻ͘ ͦͷଞ͸௨ৗͷ ϓϩύςΟʔͱಉ͡
  152. RealmͷProviderΛ֦ுؔ਺Ͱ ֦ு͢Δ fun Provider<Realm>.getAutoCloseObservable(): Observable<Realm> {
 val realm = get()


    realm.use {
 return Observable.create { emitter ->
 val instance = get()
 emitter.setCancellable {
 instance.close()
 }
 emitter.onNext(instance)
 }
 }
 } 
  153. RealmͷProviderΛ֦ுؔ਺Ͱ ֦ு͢Δ fun Provider<Realm>.getAutoCloseObservable(): Observable<Realm> {
 val realm = get()


    realm.use {
 return Observable.create { emitter ->
 val instance = get()
 emitter.setCancellable {
 instance.close()
 }
 emitter.onNext(instance)
 }
 }
 }  ֦ு͍ͨ͠ܕ Λॻ͘
  154. RealmͷProviderΛ֦ுؔ਺Ͱ ֦ு͢Δ fun Provider<Realm>.getAutoCloseObservable(): Observable<Realm> {
 val realm = get()


    realm.use {
 return Observable.create { emitter ->
 val instance = get()
 emitter.setCancellable {
 instance.close()
 }
 emitter.onNext(instance)
 }
 }
 }  ֦ு͍ͨ͠ܕ Λॻ͘ (FOFSJDTͷ ܕύϥϝʔλʔ΋ࢦఆՄ
 ϓϩύςΟʔ΋ಉ༷
  155. RealmͷProviderΛ֦ுؔ਺Ͱ ֦ு͢Δ fun Provider<Realm>.getAutoCloseObservable(): Observable<Realm> {
 val realm = get()


    realm.use {
 return Observable.create { emitter ->
 val instance = get()
 emitter.setCancellable {
 instance.close()
 }
 emitter.onNext(instance)
 }
 }
 }  ֦ு͍ͨ͠ܕ Λॻ͘ ͦͷଞ͸௨ৗͷ ؔ਺ͱಉ͡ (FOFSJDTͷ ܕύϥϝʔλʔ΋ࢦఆՄ
 ϓϩύςΟʔ΋ಉ༷
  156. ஫ҙ఺ 

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

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

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

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

  161. ΍Γա͗஫ҙ 

  162. Delegated property 

  163. ҕৡϓϩύςΟʔ 

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

  165. σϑΥϧτͷ Delegated property(Ұ෦) • Delegates.notNull • not-null͕ͩॳظԽ࣌ʹॳظԽͰ͖ͳ͍ϓϩύςΟʔ • nullͷ··ΞΫηεͨ͠Βྫ֎ •

    lazy • ஗ԆॳظԽ • ࠷ॳͷΞΫηε࣌ʹҾ਺Ͱ౉ͨ͠ϒϩοΫͷ໭Γ஋Λฦͯ͠ Ωϟογϡ͢Δ 
  166. ଟ෼͕࣌ؒ଍Γͳ͍ͷͰ 

  167. see. github.com/takuji31/ Koreference 

  168. Enjoy Kotlin Life