Pro Yearly is on sale from $80 to $50! »

Java で書かれた Android アプリを Kotlin で書き直すまでの話 / Talk of rewrite Android app for Java to Kotlin

Java で書かれた Android アプリを Kotlin で書き直すまでの話 / Talk of rewrite Android app for Java to Kotlin

集まれ Kotlin 好き ! Kotlin 愛好会 vol 2 @ DeNA

Dd17014e380450cfed5d55ff20fa3dfd?s=128

Ryutaro Miyashita

July 03, 2018
Tweet

Transcript

  1. +BWBͰॻ͔Εͨ"OESPJEΞϓϦΛ
 ,PUMJOͰॻ͖௚͢·Ͱͷ࿩ ू·Ε,PUMJO޷͖,PUMJOѪ޷ձWPM

  2. ٶԼཽେ࿠ $IBU8PSLגࣜձࣾ ΫϥΠΞϯτΞϓϦέʔγϣϯ։ൃ෦ !SZVHPP@ ޷͖ͳ,PUMJOͷػೳ͸4NBSU$BTU

  3. $IBU8PSL

  4. $IBU8PSL ‣ Ϗδωε޲͚ͷνϟοταʔϏε  8FCJ04"OESPJEσεΫτοϓΞϓϦͰఏڙ  "OESPJEΞϓϦ͸೥຤͔Β+BWB੡ ‣ ʙ·Ͱ͸5JUBOJVN +BWB4DSJQU

    ੡ͩͬͨ ‣ +BWB൛͸͔Β։ൃΛ։࢝ ‣ ,PUMJOΛݕ౼͢ΔͨΊʹͷ,PUMJOษڧձʹࢀՃ ‣ ࠾༻ڧԽத  J04"OESPJE4DBMB1)143&ͳͲ  ৄ͘͠͸8FCαΠτͰ ‣ IUUQTDPSQDIBUXPSLDPNKBSFDSVJU ‣ ؾʹͳΔ͜ͱ͕͋ͬͨΒ੠͔͚ͯԼ͍͞
  5. ,PUMJO

  6. ,PUMJO ‣ (PPHMF*0Ͱ"OESPJEެࣜݴޠԽ  ͦΕ·Ͱ΋,PUMJOͷ։ൃࣄྫ͸ଟ͋ͬͨ͘  ެࣜݴޠʹͳΔ͜ͱͰ҆৺ΛखʹೖΕͨ  طଘͷΞϓϦͱͷ෇͖߹͍ํΛͲ͏͢Δ͔ʁ ‣

    ෦෼తʹಋೖPSશ໘తʹಋೖ  ͜Εͱ͍ͬͨਖ਼ղ͸ͳ͍  ৽نϓϩδΣΫτͳΒ͹,PUMJOͰྑ͍  $IBU8PSLͰ͸શ໘తͳಋೖΛܾఆͨ͠
  7. Ͳ͔͜Β ‣ ಋೖ౰ॳ͸શ໘తͳಋೖ༧ఆ͸ͳ͔ͬͨ  খ͞ͳμΠΞϩά͔ͭΒಋೖΛ։࢝ ‣ (PPHMF*0ͷཌ೔͔Βελʔτ   ࣍ʹطଘͷը໘Λͭॻ͖׵͑ͯΈͨ

     ৽͍͠ػೳͷ௥ՃΛ,PUMJOͰॻ͍ͯΈͨ ‣ +BWBͱͷͭͳ͗ࠐΈ͕ωοΫʹͳ͍ͬͯͬͨ  ͔֬ʹ,PUMJO͸+BWBͱͷ࿈ܞ͸όονϦͰ͖Δ  ͏·͘࿈ܞ͢Δʹ͸ಛผͳҙࣝ෇͚͕ඞཁ ‣ !+WN'JFME!+WN4UBUJD!+WN0WFSMPBET ‣ SFUVSO6OJU*/45"/$& ‣ 1MBUGPSN5ZQFT
  8. !+WNʙΞ ϊςʔγϣϯ ‣ +BWB͔ΒͷΞΫηεΛҙࣝ͢Δඞཁ͕͋Δ class MyFragment : Fragment() { companion

    object { @JvmField val TAG: String = MyFragment::class.java.simpleName } @JvmOverloads fun logic(label: String = "") {} } ,PUMJO
  9. SFUVSO6OJU*/45"/$& ‣ ,PUMJOʹ͸lWPJEz͸ଘࡏ͠ͳ͍ class BusinessLogic { fun async(callback: () ->

    Unit) { // Some async logic callback(); } } BusinessLogic logic = new BusinessLogic(); logic.async(() -> { return Unit.INSTANCE; }); ,PUMJO +BWB
  10. IUUQTEJTDVTTLPUMJOMBOHPSHUKBWBJOUFSPQVOJUDMPTVSFTSFRVJSFEUPSFUVSOLPUMJOVOJU !+WN7PJEͷఏҊ ೥ʹಉ͡໰୊ఏى

  11. 1MBUGPSN5ZQFT ‣ /PO/VMM͔/VMMBCMF͔એݴ͞Ε͍ͯͳ͍ܕ  ܕ৘ใΛݟΔͱlzϚʔΫ͕෇͍͍ͯΔ ‣ "OESPJE4%,͸جຊతʹ1MBUGPSN5ZQFT ‣ !/PO/VMM!/VMMBCMF͕෇͍ͯͨΒϥοΩʔ

  12. 1MBUGPSN5ZQFT ‣ "OESPJE4%,Ͱ͋Ε͹ίʔυΛಡΜͰܕΛܾఆ͢Δ val inflater: LayoutInflater = LayoutInflater.from(this) ,PUMJO

  13. ,PUMJOͷ͏·ຯΛҾ͖ग़͍ͨ͠ ‣ ,PUMJOΛ෦෼తʹಋೖ͢Δͱ+BWBʹ΋Өڹ͕ग़Δ  ٯʹ+BWBͷ࣮૷͕,PUMJOʹ΋Өڹ͢Δ ‣ +BWB0QUJPOBMWT,PUMJO/PO/VMM/VMMBCMF5ZQF  ࣗ෼ୡ͕ॻ͍ͨ+BWBͷίʔυΛݟฦ͢ ‣

    !/PO/VMM!/VMMBCMFΞ ϊςʔγϣϯΛ෇͚͍ͯ͘ʁ ‣ ͍ͬͦͷ͜ͱ,PUMJOʹஔ͖׵͑ͨํ͕ྑ͍ͷͰ͸ͳ͍͔ʁ ‣ ͭͣͭஸೡʹ,PUMJOԽΛਐΊ͍ͯ͘  ਓͷνʔϜ಺Ͱ΋,PUMJOͷशख़౓͸όϥόϥ  ૬ޓʹϨϏϡʔΛ͠ͳ͕ΒཧղΛਂΊ͍ͯ͘  1VMM3FRVFTUʹ,PUMJOͷݴޠػೳͷઆ໌Λॻ͘
  14. ,PUMJOͷ͏·ຯΛҾ͖ग़͢ಓఔ  (PPHMF*0b  $IBU8PSL"OESPJE
 7FSTJPO 'VMM+BWB ߦ  $IBU8PSL"OESPJE


    7FSTJPO 'VMM,PUMJO ߦ Ի੠௨࿩ "OESPJE  ߦ
  15. ,PUMJOͷ͏·ຯΛҾ͖ग़ͨ݁͠Ռ ‣ ϲ݄ͰશͯͷίʔυΛ,PUMJOԽͨ͠  ͦͷؒʹػೳ௥Ճ΍ϦϑΝΫλϦϯά΋Ͱ͖ͨ  ,PUMJOԽલޙͰίʔυͷྔ͸ʹͳͬͨ ‣ νʔϜ΁ͷਁಁͱޮՌ 

    /VMM1PJOUFS&YDFQUJPOͷ๾໓ ‣ ΄΅ग़ձ͍ͬͯͳ͍ ‣ 1MBUGPSN5ZQFTͷऔΓѻ͍͕పఈ͞Εͨ ‣ +BWBͷ0QUJPOBMΑΓ΋औΓѻָ͍͕  ίʔυͷՄಡੑͷ޲্ ‣ جຊ͸WBMͰڱ͍ൣғͰWBSΛ࢖͏ͳͲͷҙࣝ෇͚
  16. ,PUMJOͷ͏·ຯΛҾ͖ग़ͨ͢Ίʹ ‣ ,PUMJOଆͷ࣮૷΋ݟͨํ͕ྑ͍  ྫ͑͹NBQˠUP-JTUͷྲྀΕ ‣ +BWBͷ4USFBNΛ࢖ͬͯΔͱ͍ͭ΍Γͨ͘ͳΔ ‣ ࣮ࡍ͸NBQͷ࣌఺Ͱ-JTU3͕ಘΒΕΔ val

    results: List<R> = someCollection .map { it.convert() } .toList() ,PUMJO
  17. ,PUMJOͷ͏·ຯΛҾ͖ग़ͨ͢Ίʹ ‣ 4IPX,PUMJO#ZUFDPEFˠ%FDPNQJMF͢Δ val source = listOf(1, 2, 3, 4,

    5) val results: List<String> = source .map { it.toString(10) } ,PUMJO UP-JTUແ UP-JTU༗
  18. ,PUMJOͷ͏·ຯΛҾ͖ग़͠ଛͶͨࣄྫ ‣ ,PUMJOͱ"OESPJE +%, ͷ"1*͕ಉ໊͡લ ‣ ਖ਼ղ͸൪ԼͷGPS&BDIͰͨ͠ʂ  ൪Լ͸LPUMJODPMMFDUJPOTGPS&BDI ‣

    .BQͷ֦ுؔ਺ͱͯ͠ఆٛ͞Ε͍ͯΔ  ্͔ΒͭΊ͸KBWBVUJM.BQGPS&BDI ‣ "OESPJEͰ࢖͑ΔΑ͏ʹͳͬͨͷ͸-W͔Β ‣ /P$MBTT%FG'PVOE&SSPS͕ൃੜͨ͠
  19. ࠷ޙʹ

  20. ࠷ޙʹ ‣ طଘͷΞϓϦ΋ஈ֊తʹ,PUMJOԽ͍͚ͯ͠Δ ͨ   +BWBͱͷ૬ޓӡ༻ੑͷߴ͞ ‣ த్൒୺ʹಋೖ͢Δ͙Β͍ͳΒ͹શͯॻ͖׵͍͑ͨ 

    +BWBͱ,PUMJOؒͰͦΕͧΕΛҙࣝ͢Δखؒ ‣ ਓखͰؾΛ͚ͭͳ͍ͱ͍͚ͳ͍Օॴ͸ඞͣࣄނ͕ੜ·ΕΔ ‣ ଞνʔϜ͔Βݟͨ৺ཧతোน͕Լ͕ͬͨ  ෭࣍తͳޮՌ ‣ J04νʔϜ͕,PUMJOͷίʔυΛಡΜͰ4XJGUʹҠ২ ‣ 4DBMB ؚ4DBMB+4 5ZQF4DSJQU࢖͍΋༰қʹಡΊΔ
  21. ͓͠·͍