Kolin Modifiers

Kolin Modifiers

「KotlinのLT会!Kotlin入門者の集い」で発表したやつの全部込み版です。

33f6da3f9e2530fff68c72e33f313839?s=128

kissybnts

June 26, 2017
Tweet

Transcript

  1. Kolin Modifiers ,PUMJOͷ-5ձʂ,PUMJOೖ໳ऀͷू͍

  2. Name: Company: Role: Language: Kotlin: ͖ͩ͠ ServerSideEngineer, BridgeEngineer Java 1.0͘Β͍͔Β

  3. None
  4. None
  5. ,PUMJOʹ͸ؔ਺ʹ͚ͭΔ͜ͱ͕Ͱ͖Δ .PEJpFS म০ࢠ ͕͍Ζ͍Ζ͋Δ

  6. ‣ infix ‣ inline ‣ noinline ‣ crossinline ‣ reified

    ‣ tailrec
  7. ͜ΕΒΛઆ໌͠·͢

  8. 7JTJCJMJUZ.PEJpFST͸άά͍ͬͯͩ͘͞

  9. infix

  10. Ҿ਺͕ͭͷϝιουΛ ׅހͳ͠Ͱ࢖͑ΔΑ͏ʹ͢Δ

  11. None
  12. infix Modifier

  13. StringΫϥεͷ֦ுؔ਺

  14. Ҿ਺͸Ұͭ

  15. ͜Μͳ෩ʹ࢖͑Δ

  16. w ϝϯόؔ਺·ͨ͸֦ுؔ਺ w Ҿ਺͕ͭ w infixΛؔ਺ʹ͚ͭΔ ࢖༻৚݅

  17. ΋ͪΖΜͭͳ͛ͯ΋࢖͑Δ

  18. ͜ΕΛ

  19. ͜͏ͯ͠

  20. ͜ΕΛ

  21. ͜͏͢Δ

  22. ͪͳΈʹ

  23. ͜Ε͸ͩΊ

  24. ͜Ε͸0,

  25. inline

  26. 'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ޲্ͤ͞Δ

  27. None
  28. 'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ޲্ͤ͞Δ

  29. 'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ޲্ͤ͞Δ

  30. 'VODUJPOMJUFSBMͱ͸ʁ

  31. None
  32. ແ໊ؔ਺΍

  33. ϥϜμࣜͰ౉͞ΕΔ ؔ਺ͷ͜ͱ

  34. ΠϯϥΠϯల։ͱ͸ʁ

  35. ؆୯ͳൺֱͰઆ໌

  36. None
  37. StringΫϥεͷ֦ுؔ਺

  38. StringΛҾ਺ʹͱͬͯStringΛฦؔ͢਺

  39. Ҿ਺ͷؔ਺Λ࣮ߦͯ͠ɺtoUpperCase()ͯ͠ฦ͢

  40. inline Modifier

  41. ͦΕҎ֎͸Ұॹ

  42. None
  43. ݁Ռ͸ಉ͡

  44. None
  45. ͦΕͧΕ࣮ߦ࣌ʹͲ͏ͳΔͷ͔ʁ

  46. inlineແ͠ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠આ໌͠·͢ */

  47. inlineແ͠ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  48. SFDFJWFSͷ஋Λ֨ೲ inlineແ͠ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  49. ֦ுؔ਺ͱಉ໊͡લͷؔ਺͕࡞੒͞Εݺ͹ΕΔ inlineແ͠ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  50. ୈҰҾ਺ʹSFDFJWFS inlineແ͠ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  51. ؔ਺ΦϒδΣΫτͷΠϯελϯεΛ࡞੒ׂͯ͠Γ౰ͯ inlineແ͠ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  52. /* આ໌ͷͨΊʹ؆ུతʹهड़ͨ͠ΫϥεͰ͢ */ inlineແ͠

  53. JOWPLFͱ͍͏ϝιουΛ΋ͭ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨ͠ΫϥεͰ͢ */ inlineແ͠

  54. த਎͸ϥϜμࣜͰ౉ͨ͠ॲཧ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨ͠ΫϥεͰ͢ */ inlineແ͠

  55. /* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠਺Ͱ͢ */ inlineແ͠

  56. ϥϜμࣜͰ౉ͨ͠ॲཧΛ΋ͭΠϯελϯε /* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠਺Ͱ͢ */ inlineແ͠

  57. ϥϜμࣜͰ౉ͨ͠ॲཧΛ࣮ߦ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠਺Ͱ͢ */ inlineແ͠

  58. toUpperCase()Λͯ͠ฦ͢ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠਺Ͱ͢ */ inlineແ͠

  59. inlineແ͠ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  60. ϝιουݺͼग़͠ͷίετ inlineແ͠ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  61. Πϯελϯεੜ੒ͷίετ inlineແ͠ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  62. None
  63. /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠આ໌͠·͢ */ inline͋Γ

  64. inline͋Γ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  65. ಉ͡ inline͋Γ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  66. ϥϜμࣜͰ౉ͨ͠ॲཧ inline͋Γ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  67. toUpperCase()ͯ͠ऴΘΓ inline͋Γ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  68. ΠϯϥΠϯల։ inline͋Γ /* ཧղ͠΍͍͢Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */

  69. 'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ޲্ͤ͞Δ

  70. Πϯελϯεͷੜ੒ίετ ϝιουݺͼग़͠ͷίετ

  71. Πϯελϯεͷੜ੒ίετ ϝιουݺͼग़͠ͷίετ

  72. None
  73. ؔ࿈͢Δಛ௃

  74. ϥϜμࣜͷதͰreturnΛ࢖ͬͯ ݺͼग़͠ݩͷؔ਺Λൈ͚Δ͜ͱ͕Ͱ͖Δ

  75. inlineͳ͠

  76. None
  77. ίϯύΠϧΤϥʔ

  78. ͜ͷதͰݺͼग़͠ݩͷؔ਺͔Βൈ͚Α͏ͱ͢Δ

  79. inline͋Γ

  80. None
  81. σϑΥϧτͰinlineʹͳΒͳ͍ͷ͸ͳͥʜ

  82. ΠϯϥΠϯԽ͢Δؔ਺͕େ͖͍ͱ ੜ੒͞ΕΔίʔυ͕ංେԽ͢ΔՄೳੑ͕͋Δ

  83. ϥϜμࣜ಺Ͱͷreturn͕ޡղΛট͖΍͍͢ /* ͜Ε͸ओ؍Ͱ͢ */

  84. noinline

  85. ΠϯϥΠϯԽ͠ͳ͍ؔ਺ΛࢦఆͰ͖Δ

  86. None
  87. noinline Modifier

  88. ͜ͷؔ਺͸ΠϯϥΠϯల։͞Εͳ͍

  89. ͬͪ͜ͷؔ਺͸ΠϯϥΠϯల։͞ΕΔ

  90. crossinline

  91. Ҿ਺ͷؔ਺Λinlineؔ਺಺Ҏ֎ͷจ຺Ͱ ࣮ߦͰ͖ΔΑ͏ʹ͢Δ

  92. None
  93. None
  94. ౉͞Εͨؔ਺Λ

  95. Invokableܕͷಗ໊Ϋϥεͷ

  96. injectedFunction()ͱ͍͏ϝιουͷ࣮૷ʹ࢖͍͍ͨ

  97. abstract class Invokable { fun invoke(arg: String): String { val

    before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" }
  98. abstract class Invokable { fun invoke(arg: String): String { val

    before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" } injectedFunction()ͱ͍͏abstractϝιου
  99. abstract class Invokable { fun invoke(arg: String): String { val

    before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" } invoke()ͱ͍͏ϝιουͷதͰ
  100. abstract class Invokable { fun invoke(arg: String): String { val

    before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" } ࢖͏
  101. ίϯύΠϧΤϥʔ

  102. None
  103. None
  104. crossinline Modifier

  105. ࢖͑Δ

  106. reified

  107. inlineؔ਺಺Ͱ ܕύϥϝʔλʹΞΫηεՄೳʹ͢Δ

  108. ܕύϥϝʔλ

  109. ClassΫϥεΛҾ਺ʹऔΔ

  110. ಉ͡ܕͷListΛฦ͢

  111. ౉͞ΕͨํʹΑͬͯॲཧΛ෼͚Δ

  112. None
  113. None
  114. None
  115. inline Modifier

  116. reified Modifier

  117. Ҿ਺͸ແ͠

  118. ܕύϥϝʔλ͕ར༻Ͱ͖Δ

  119. None
  120. ܕΛએݴ͢Δ

  121. Ҿ਺ͳ͠Ͱ࣮ߦ

  122. ܕΛਪ࿦͢Δ

  123. ܕΛࢦఆ࣮ͯ͠ߦ

  124. None
  125. None
  126. ActivityΫϥεͷ֦ுؔ਺

  127. reifiedΛ͚ͭͯΞΫηεՄೳʹ

  128. Activity.findViewById()ͷ໭Γ஋Λ

  129. ܕύϥϝʔλͰࢦఆ͞ΕΔܕʹΩϟετͯ͠ฦ͢

  130. ܕએݴΛ͢Δ

  131. ຖճΩϟετΛॻ͘ඞཁ͕ͳ͘ͳΔ

  132. None
  133. tailrec

  134. ຤ඌ࠶ؼͳؔ਺ͷ࣮ߦΛ࠷దԽ͢Δ

  135. ຤ඌ࠶ؼ

  136. wؔ਺ܕݴޠͰΑ͘ݟΔελΠϧ wϧʔϓͷॲཧΛ୅ସ͢Δ wؔ਺ͷ࠷ޙʹࣗ਎Λݺͼग़͢

  137. None
  138. tailrec Modifier

  139. දࣔ͢Δϝοηʔδ

  140. දࣔ͢Δճ਺

  141. ճ਺͕0ҎԼͷ࣌͸return

  142. ϝοηʔδΛදࣔͯ͠

  143. ճ਺ΛݮΒͯࣗ͠਎Λݺͼग़͢

  144. tailrecແ͠Ͱ΋ίϯύΠϧͰ͖Δ

  145. ͳʹ͕ҧ͏ͷ͔ʁ

  146. tailrecແ͠ͷ৔߹

  147. None
  148. ίϯύΠϧ͞Εͯ΋΄΅ಉ͡

  149. 4UBDL0WFS'MPX͕ى͖ΔՄೳੑ͕ߴ͍

  150. None
  151. tailrec͋Γͷ৔߹

  152. while͕࣮ߦ͞ΕΔ

  153. ࣗ਎Λݺͼग़͞ͳ͍

  154. 4UBDL0WFS'MPX͕ى͖ΔՄೳੑ͕௿͘ͳΔ

  155. None
  156. 4UBDL0WFS'MPX͕ى͖ͳ͍Θ͚Ͱ͸ͳ͍

  157. Ҏ্

  158. &OKPZ,PUMJO