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

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

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

Cluex社主催 LT大会 発表資料

kazakago

May 19, 2017
Tweet

More Decks by kazakago

Other Decks in Programming

Transcript

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

    ɹɹɹɹɹͷ͢͢Ί

    View full-size slide

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

    View full-size slide

  3. 8IBU`Tɹɹɹɹɹ

    View full-size slide

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

    View full-size slide

  5. "OESPJEͷୈҰݴޠʹʂ
    ࡢ೔ʢʂʣ(PPHMF*0ʹͯ

    "OESPJE։ൃͷୈҰڃݴޠʹͳΔͱൃද͞Ε·ͨ͠

    View full-size slide

  6. ͷ
    ྑ͍ͱ͜Ζ

    View full-size slide

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

    View full-size slide

  8. 4QSJOH'SBNFXPSL

    View full-size slide

  9. ܕਪ࿦
    ม਺͸+BWBͱҧ͍WBSͱ͍͏҉໧తͳܕએݴΛߦ͏ɻ

    ίʔυͷ࠷ޙʹʮʯΛ෇͚Δඞཁ͸ͳ͍ɻ
    w +BWB
    String value = new String("JavaͩΑʔʂ");
    w ,PUMJO
    var value = String("KotlinͩΑʔʂ")

    View full-size slide

  10. ܕਪ࿦
    KBWBʹ͓͚ΔpOBMम০ࢠ͸,PUMJOͰWBMͱ͍͏ม਺એݴͰه
    ड़͢Δɻ

    WBMͰ͍͍ͱ͜ΖΛWBSͰهड़͢Δͱ*%&͔Βܯࠂ΋දࣔ͞Ε
    ΔͨΊKBWBΑΓpOBM͕పఈͰ͖Δʢؾ͕͢Δʣ
    w +BWB
    final String value = new String("JavaͩΑʔʂ");
    w ,PUMJO
    val value = String("KotlinͩΑʔʂ")

    View full-size slide

  11. ϥϜμࣜ
    ,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("Ϙλϯԡ͞Εͨʂ");

    }

    });

    View full-size slide

  12. ϥϜμࣜ
    ,PUMJOͰ͸͜͏ɻ
    w ,PUMJO
    val button = Button(this)

    button.setOnClickListener {

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

    }


    View full-size slide

  13. /VMM҆શ
    +BWBͩͱωετ͞Εͨਂ͍֊૚ͷม਺ΛऔΓग़ͦ͏
    ͱ͢ΔͱҎԼͷΑ͏ͳίʔυʹͳΔɻ

    ͜Μͳ࣌ʹى͜Γ͕ͪͳͷ͕ɺɺ
    w +BWB
    ObjectD getObjectD(ObjectA objectA) {

    return objectA.getObjectB().getObjectC().getObjectD();

    }

    View full-size slide

  14. /VMM҆શ
    NullPointerException

    View full-size slide

  15. /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;

    }


    View full-size slide

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

    return objectA?.objectB?.objectC?.objectD

    }


    View full-size slide

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

    View full-size slide

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

    return (this % 2 == 0)

    }
    ˣ
    val counter: Int = 1

    val isEven = counter.isEvenNumber()

    View full-size slide

  19. ͦͷଞʹ΋ʜ
    w ίϧʔνϯ
    w σϑΥϧτҾ਺
    w ετϦʔϜૢ࡞ؔ਺
    w σʔλΫϥε
    w ඇݕࠪྫ֎
    w KBWBTDSJQU΁ͷτϥΠϯεύΠϧ
    w ,PUMJO/BUJWF
    w FUD

    View full-size slide

  20. ͷ
    l·ͩzྑ͘ͳ͍ͱ͜Ζ

    View full-size slide

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

    View full-size slide

  22. Ұ෦ͷϥΠϒϥϦ͸

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide