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

Java で書かれた Android アプリを Kotlin で書き直すまでの話 / ...

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

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

Ryutaro Miyashita

July 03, 2018
Tweet

More Decks by Ryutaro Miyashita

Other Decks in Technology

Transcript

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

    ੡ͩͬͨ ‣ +BWB൛͸͔Β։ൃΛ։࢝ ‣ ,PUMJOΛݕ౼͢ΔͨΊʹͷ,PUMJOษڧձʹࢀՃ ‣ ࠾༻ڧԽத  J04"OESPJE4DBMB1)143&ͳͲ  ৄ͘͠͸8FCαΠτͰ ‣ IUUQTDPSQDIBUXPSLDPNKBSFDSVJU ‣ ؾʹͳΔ͜ͱ͕͋ͬͨΒ੠͔͚ͯԼ͍͞
  2. ,PUMJO ‣ (PPHMF*0Ͱ"OESPJEެࣜݴޠԽ  ͦΕ·Ͱ΋,PUMJOͷ։ൃࣄྫ͸ଟ͋ͬͨ͘  ެࣜݴޠʹͳΔ͜ͱͰ҆৺ΛखʹೖΕͨ  طଘͷΞϓϦͱͷ෇͖߹͍ํΛͲ͏͢Δ͔ʁ ‣

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

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

    object { @JvmField val TAG: String = MyFragment::class.java.simpleName } @JvmOverloads fun logic(label: String = "") {} } ,PUMJO
  5. 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
  6. ,PUMJOͷ͏·ຯΛҾ͖ग़͍ͨ͠ ‣ ,PUMJOΛ෦෼తʹಋೖ͢Δͱ+BWBʹ΋Өڹ͕ग़Δ  ٯʹ+BWBͷ࣮૷͕,PUMJOʹ΋Өڹ͢Δ ‣ +BWB0QUJPOBMWT,PUMJO/PO/VMM/VMMBCMF5ZQF  ࣗ෼ୡ͕ॻ͍ͨ+BWBͷίʔυΛݟฦ͢ ‣

    !/PO/VMM!/VMMBCMFΞ ϊςʔγϣϯΛ෇͚͍ͯ͘ʁ ‣ ͍ͬͦͷ͜ͱ,PUMJOʹஔ͖׵͑ͨํ͕ྑ͍ͷͰ͸ͳ͍͔ʁ ‣ ͭͣͭஸೡʹ,PUMJOԽΛਐΊ͍ͯ͘  ਓͷνʔϜ಺Ͱ΋,PUMJOͷशख़౓͸όϥόϥ  ૬ޓʹϨϏϡʔΛ͠ͳ͕ΒཧղΛਂΊ͍ͯ͘  1VMM3FRVFTUʹ,PUMJOͷݴޠػೳͷઆ໌Λॻ͘
  7. ,PUMJOͷ͏·ຯΛҾ͖ग़ͨ݁͠Ռ ‣ ϲ݄ͰશͯͷίʔυΛ,PUMJOԽͨ͠  ͦͷؒʹػೳ௥Ճ΍ϦϑΝΫλϦϯά΋Ͱ͖ͨ  ,PUMJOԽલޙͰίʔυͷྔ͸ʹͳͬͨ ‣ νʔϜ΁ͷਁಁͱޮՌ 

    /VMM1PJOUFS&YDFQUJPOͷ๾໓ ‣ ΄΅ग़ձ͍ͬͯͳ͍ ‣ 1MBUGPSN5ZQFTͷऔΓѻ͍͕పఈ͞Εͨ ‣ +BWBͷ0QUJPOBMΑΓ΋औΓѻָ͍͕  ίʔυͷՄಡੑͷ޲্ ‣ جຊ͸WBMͰڱ͍ൣғͰWBSΛ࢖͏ͳͲͷҙࣝ෇͚
  8. ,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༗
  9. ,PUMJOͷ͏·ຯΛҾ͖ग़͠ଛͶͨࣄྫ ‣ ,PUMJOͱ"OESPJE +%, ͷ"1*͕ಉ໊͡લ ‣ ਖ਼ղ͸൪ԼͷGPS&BDIͰͨ͠ʂ  ൪Լ͸LPUMJODPMMFDUJPOTGPS&BDI ‣

    .BQͷ֦ுؔ਺ͱͯ͠ఆٛ͞Ε͍ͯΔ  ্͔ΒͭΊ͸KBWBVUJM.BQGPS&BDI ‣ "OESPJEͰ࢖͑ΔΑ͏ʹͳͬͨͷ͸-W͔Β ‣ /P$MBTT%FG'PVOE&SSPS͕ൃੜͨ͠
  10. ࠷ޙʹ ‣ طଘͷΞϓϦ΋ஈ֊తʹ,PUMJOԽ͍͚ͯ͠Δ ͨ   +BWBͱͷ૬ޓӡ༻ੑͷߴ͞ ‣ த్൒୺ʹಋೖ͢Δ͙Β͍ͳΒ͹શͯॻ͖׵͍͑ͨ 

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