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

まだJavaで消耗してるの?Kotlinのすすめ

 まだJavaで消耗してるの?Kotlinのすすめ

Cluex社主催 LT大会 発表資料

16d3962b8f11b7e801dacb129d20d8dd?s=128

KazaKago

May 19, 2017
Tweet

More Decks by KazaKago

Other Decks in Programming

Transcript

  1. ·ͩ+BWBͰফ໣ͯ͠Δͷʁ
 ɹɹɹɹɹͷ͢͢Ί

  2. ࣗݾ঺հ w ాଜݠհʢ!,B[B,BHPʣ w גࣜձࣾΠάχεॴଐ w ࿀Ѫɾࠗ׆ϚονϯάαʔϏε ʮXJUIʯ։ൃϝϯόʔ w "OESPJE։ൃྺɿ͍͍ͩͨ೥͘Β͍

  3. ࣗݾ঺հ

  4. 8IBU`Tɹɹɹɹɹ

  5. ɹɹɹɹɹͬͯԿʁ w +FU#SBJOT͕ࣾ։ൃͨ͠+BWB׬શޓ׵ݴޠ w *OUFMMJK*%&"΍3VCZ.JOFɺ1IQ4UPSNͳͲͷ*%&ʢ౷߹։ൃ؀ ڥʣΛ࡞ͬͯΔνΣίʹ͋Δձࣾ w ݱࡏͷόʔδϣϯ͸ w Φʔϓϯιʔε

    "QBDIFϥΠηϯε
  6. "OESPJEͷୈҰݴޠʹʂ ࡢ೔ʢʂʣ(PPHMF*0ʹͯ
 "OESPJE։ൃͷୈҰڃݴޠʹͳΔͱൃද͞Ε·ͨ͠

  7. ͷ ྑ͍ͱ͜Ζ

  8. ಋೖͷෑډͷ௿͞ w (SBEMF΍.BWFOͳͲͷҰൠతͳϏϧυπʔϧΛಋ ೖ͍ͯ͠Ε͹͙͢ʹಋೖՄೳ w "OESPJEϓϩδΣΫτͳΒ΄΅͢΂ͯͷϓϩδΣΫτͰಋೖՄೳ w *OUFMMJK*%&"ͰϋΠϨϕϧͳαϙʔτ͕͞Ε͍ͯͯ +BWBˠ,PUMJOͷίϯόʔλʔ΋෇ଐ͞Ε͓ͯΓɺͦ Ε͕͔ͳΓ༏ल

    w "OESPJE4UVEJP΋*OUFMMJK*%&"ޓ׵Ͱ+FUCSBJOT͕ࣾ࡞͍ͬͯΔ
  9. 4QSJOH'SBNFXPSL

  10. ܕਪ࿦ ม਺͸+BWBͱҧ͍WBSͱ͍͏҉໧తͳܕએݴΛߦ͏ɻ
 ίʔυͷ࠷ޙʹʮʯΛ෇͚Δඞཁ͸ͳ͍ɻ w +BWB String value = new String("JavaͩΑʔʂ");

    w ,PUMJO var value = String("KotlinͩΑʔʂ")
  11. ܕਪ࿦ KBWBʹ͓͚ΔpOBMम০ࢠ͸,PUMJOͰWBMͱ͍͏ม਺એݴͰه ड़͢Δɻ
 WBMͰ͍͍ͱ͜ΖΛWBSͰهड़͢Δͱ*%&͔Βܯࠂ΋දࣔ͞Ε ΔͨΊKBWBΑΓpOBM͕పఈͰ͖Δʢؾ͕͢Δʣ w +BWB final String value

    = new String("JavaͩΑʔʂ"); w ,PUMJO val value = String("KotlinͩΑʔʂ")
  12. ϥϜμࣜ ,PUMJOͰ͸ϥϜμ͕ࣜ࢖͑Δɻ
 "OESPJEͷϘλϯΠϕϯτ͸+BWBͰ͸ҎԼͷΑ͏ʹ͜͏ ॻ͕͘ɺɺɺ w +BWB +BWB  Button button

    = new Button(this);
 button.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 System.out.print("Ϙλϯԡ͞Εͨʂ");
 }
 });
  13. ϥϜμࣜ ,PUMJOͰ͸͜͏ɻ w ,PUMJO val button = Button(this)
 button.setOnClickListener {


    print("Ϙλϯԡ͞Εͨʂ")
 }

  14. /VMM҆શ +BWBͩͱωετ͞Εͨਂ͍֊૚ͷม਺ΛऔΓग़ͦ͏ ͱ͢ΔͱҎԼͷΑ͏ͳίʔυʹͳΔɻ
 ͜Μͳ࣌ʹى͜Γ͕ͪͳͷ͕ɺɺ w +BWB ObjectD getObjectD(ObjectA objectA) {


    return objectA.getObjectB().getObjectC().getObjectD();
 }
  15. /VMM҆શ NullPointerException

  16. /VMM҆શ w +BWB ObjectD getObjectD(ObjectA objectA) {
 if (objectA !=

    null) {
 ObjectB objectB = objectA.getObjectB();
 if (objectB != null) {
 ObjectC objectC = objectB.getObjectC();
 if (objectC != null) {
 return objectC.getObjectD();
 }
 }
 }
 return null;
 }

  17. /VMM҆શ

  18. /VMM҆શ ,PUMJOͰಉ౳ͷίʔυΛॻ͘৔߹ϫϯϥΠφʔͰॻ͚ Δ w ,PUMJO fun getObjectD(objectA: ObjectA?): ObjectD? {


    return objectA?.objectB?.objectC?.objectD
 }

  19. /VMM҆શ w Λ͚ͭΔͱ/VMMΛ୅ೖͰ͖Δ var value: String? = null w Λ͚ͭͳ͍ͱ/VMMΛ୅ೖͰ͖ͳ͍

    var value: String = "hogehoge"
  20. ֦ுؔ਺ w طଘͷΫϥεΠϯελϯεʹϝιουΛੜ΍͢͜ͱ ͕ग़དྷΔ fun Int.isEvenNumber(): Boolean {
 return (this

    % 2 == 0)
 } ˣ val counter: Int = 1
 val isEven = counter.isEvenNumber()
  21. ͦͷଞʹ΋ʜ w ίϧʔνϯ w σϑΥϧτҾ਺ w ετϦʔϜૢ࡞ؔ਺ w σʔλΫϥε w

    ඇݕࠪྫ֎ w KBWBTDSJQU΁ͷτϥΠϯεύΠϧ w ,PUMJO/BUJWF w FUD
  22. ͷ l·ͩzྑ͘ͳ͍ͱ͜Ζ

  23. +BWBͷ஌ࣝ͸ඞཁ w +BWBˡˠ,PUMJOͰ૬ޓʹ࢖͑Δ͕Ώ͑ʹݴޠΛ·ͨ ͙ࡍʹ֮͑ͯஔ͔ͳ͚Ε͹ͳΒͳ͍͓࡞๏͸ଟ͍ɻ w ಛʹϑϨʔϜϫʔΫ͕+BWBͰॻ͔Ε͍ͯΔ৔߹͸͔ ͳΓ஫ҙ͢Δඞཁ͕͋Γɻ w +BWBͷ஌͕ࣝͳ͍ͱͳͥΤϥʔ͕ൃੜ͍ͯ͠Δͷ ͔൑அ͕೉͍͜͠ͱ΋͋Δ

  24. Ұ෦ͷϥΠϒϥϦ͸
 ͏·͘ಈ࡞͠ͳ͍ࣄ͕͋Δ w ΄ͱΜͲͷϥΠϒϥϦ͸໰୊ͳ͘ಈ࡞͢Δ͕ɺίʔ υͷࣗಈੜ੒Λߦ͏ϥΠϒϥϦ͸Ұ෦ಛघͳॻ͖ํ Λ͠ͳ͍ͱಈ࡞͠ͳ͍͜ͱ͕͋Δ w +BWBϥΠϒϥϦͩͱ,PUMJOతʹ͸৑௕ͳهड़Λͤ͟ ΔΛಘͳ͍͜ͱ͕͋Δ

  25. ͷ
 ·ͱΊ

  26. ·ͱΊ w +BWBΑΓݴޠ࢓্༷ʹ҆શ͔ͭ؆ܿʹॻ͚Δ w طଘͷ+BWBͱࠞࡏͰ͖ɺίϯόʔλʔ΋͋ΔͨΊ Ҡߦ͸ൺֱత༰қ w ॳֶऀ͸+BWB͔Βֶश͢΂͖ w ໊લ͕ͳΜͱͳ͔͘Θ͍͍ʢ೔ຊਓฒײʣ

  27. ͋Γ͕ͱ͏͍͟͝·ͨ͠