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

Kotlin初心者向けハンズオン #3 / Kotlin Hands-on for Beginners

shanonim
April 15, 2018

Kotlin初心者向けハンズオン #3 / Kotlin Hands-on for Beginners

2018.04.15
Kotlin初心者向けハンズオン #3
https://kotlin.connpass.com/event/79344/

shanonim

April 15, 2018
Tweet

More Decks by shanonim

Other Decks in Technology

Transcript

  1. ,PUMJO
    ॳ৺ऀ޲͚ϋϯζΦϯ

    !TIBOPOJN
    UFSBUBJM@LU

    View full-size slide

  2. ࣗݾ঺հ
    ࣰݪ߂ޫ
    !TIBOPOJN
    ,PUMJOྺ೥ϲ݄

    View full-size slide

  3. w ΦʔΨχοΫ৯඼ͷ&$αʔϏεʲ0JTJYʳΛఏڙ
    w 8FCJ04"OESPJE

    View full-size slide

  4. w ,PUMJOͰ"OESPJEΞϓϦΛϑϧϦχϡʔΞϧͨ͠࿩
    w IUUQDSFBUPSTPJTJYDPKQFOUSZ
    w IUUQTSFDSVJUPJTJYEPUEBJDIJDPKQKPCFOHJOFFS

    View full-size slide

  5. ,PUMJOॳ৺ऀ޲͚ϋϯζΦϯ

    View full-size slide

  6. ࠓ೔΍Δ͜ͱ
    ,PUMJOʹ͍ͭͯ
    ϋϯζΦϯ
    ΦϦδφϧϓϩμΫτ։ൃʢ΋͘΋͘ձʣ

    View full-size slide

  7. ,PUMJOʹ͍ͭͯ

    View full-size slide

  8. ྲྀߦͬͯΔײ
    +7.
    "OESPJE
    OVMM҆શ
    ࠷ۙΑ͘ฉ͘
    #FUUFS+BWB ৽͍͠ݴޠ
    αʔόʔαΠυ
    4QSJOH'SBNFXPSL
    ໊લ͕͔Θ͍͍
    ͜ͱΓΜ
    ͔Θ͍͍
    ੩తܕ෇͚
    ΦϒδΣΫτࢦ޲
    ܕਪ࿦
    ͔Θ͍͍
    ॳ৺ऀͰ΋Ͱ͖Δʁ
    J04ΞϓϦ΋࡞ΕΔ
    +4τϥϯείϯύΠϧ
    ͔Θ͍͍
    Φʔϓϯιʔε

    View full-size slide

  9. ϓϩάϥϛϯάݴޠ
    w ੩తܕ෇͚ݴޠ
    w ίϯύΠϧ࣌ʹܕͷ੔߹ੑΛݕࠪ
    w γεςϜͷݎ࿚ੑ޲্
    w ΦϒδΣΫτࢦ޲
    w +7.ݴޠ

    View full-size slide

  10. ಛ௃
    w ʰ#FUUFS+BWBʱ
    w +BWBΑΓ΋҆શͰ؆ܿʹॻ͘͜ͱ͕Ͱ͖Δݴޠ
    w +BWB΍ͦͷଞ+7.ݴޠܦݧऀ͕࢝Ί΍͍͢ݴޠ

    View full-size slide

  11. w ܕਪ࿦
    w ιʔείʔυ಺શͯͷม਺ͷํΛ໌ࣔతʹॻ͘ඞཁ͕ͳ͍
    w จ຺͔Βม਺ͷํΛࣗಈతʹܾఆ͠ɺܕͷએݴΛলུ͢Δ
    val x = 1
    ม਺Λ੔਺ܕͰॳظԽ͍ͯ͠Δˠ*OUܕͰ͋Δͱ൑அ͞ΕΔ
    val x = "Hello World!"
    ม਺ΛจࣈྻܕͰॳظԽ͍ͯ͠Δˠ4USJOHܕͰ͋Δͱ൑அ͞ΕΔ
    ಛ௃

    View full-size slide

  12. w OVMM҆શʢOVMMڐ༰ܕͷαϙʔτʣ
    w /PNPSF/VMM1PJOUFS&YDFQUJPO
    w OVMMڐ༰ܕΛαϙʔτ͢Δ͜ͱͰɺ/1&ΤϥʔΛ࣮ߦ࣌Τϥʔ͔Βɹɹɹ
    ίϯύΠϧ࣌Τϥʔʹͯ͠ղܾ
    /* Java */
    int strLen(String s) {
    return s.length();
    }
    /* Kotlin */
    fun strLen(s: String) = s.length
    OVMMΛҾ਺ͱͯ͠ݺͼग़͢ͱ/1&
    OVMMΛҾ਺ͱͯ͠ݺͼग़͢͜ͱ͕ڐՄ͞Εͳ͍
    ʢίϯύΠϧΤϥʔʣ
    /* Kotlin */
    fun strLen(s: String?) = ...
    Ҿ਺ʹOVMM͕ೖΔ͜ͱΛڐՄ͢ΔʢOVMMBCMFʣͷ৔߹͸
    ܕʹٙ໰ූΛ෇͚ͯ໌ࣔ͢Δ
    ʢʹ໌ࣔ͠ͳ͚Ε͹ɺશͯͷܕ͸OVMMඇڐ༰ܕʹͳΔʣ
    ಛ௃

    View full-size slide

  13. w +BWBͱͷ૬ޓӡ༻ੑ
    w JOUFSPQFSBCMFXJUI+BWB +BWBͱ׬શʹ૬ޓӡ༻Մೳ

    w ಉ͡ϓϩδΣΫτʹ+BWBͷίʔυͱ,PUMJOͷίʔυ͕ࠞࡏͰ͖Δ
    w ϓϩδΣΫτͷҰ෦͔Β,PUMJOԽՄೳˠಋೖ͕༰қ
    ಛ௃

    View full-size slide

  14. ։ൃݩ
    w +FU#SBJOT
    w *OUFMMJ+*%&"ͷ։ൃݩ
    w "OESPJEͷ։ൃݴޠͱͯ͠ਖ਼ࣜ࠾༻
    w IUUQTEFWFMPQFSBOESPJEDPNLPUMJOJOEFYIUNM

    View full-size slide

  15. ໊લͷ༝དྷ
    w ίτϦϯౡ
    w ʬ,PUMJOʗЮѓїѐэђʭϩγΞ࿈๜๺੢෦ɺϑΟϯϥϯυ࿷Ԟʹ͋Δౡ
    w ౬෸͔͠ͷ΍͔ΜΛද͢ϑΟϯϥϯυޠˠ,PUMJO

    View full-size slide

  16. ϦϦʔε
    w ৽͍͠ݴޠ
    w ೥݄ʹ,PUMJOϓϩδΣΫτΛΞφ΢ϯε ೥

    w 1ZUIPO೥ ೥

    w 3VCZ೥ ೥

    w 4DBMB೥ ೥

    w ೥݄ʹਖ਼ࣜϦϦʔεʢਖ਼ࣜϦϦʔε͔Β೥ʣ

    View full-size slide

  17. ։ൃ؀ڥ
    w 8FC
    w 5SZ,PUMJO
    w *%&
    w *OUFMMJ+*%&"
    w &DMJQTF
    w "OESPJE4UVEJP "OESPJEΞϓϦ։ൃ༻

    View full-size slide

  18. ׆༂ͷ෼໺
    w .PCJMF
    w "OESPJE
    w ,PUMJO/BUJWF
    w IUUQTLPUMJOMBOHPSHEPDTSFGFSFODFOBUJWFPWFSWJFXIUNM
    w 8FC
    w ,PUMJOGPS+BWB4DSJQU
    w 4FSWFS4JEF
    w 4QSJOH'SBNFXPSL
    w IUUQTTQSJOHJPCMPHJOUSPEVDJOHLPUMJOTVQQPSUJOTQSJOHGSBNFXPSL

    View full-size slide

  19. ֶशํ๏
    w ॻ੶
    w ,PUMJOೖ໳·Ͱͷॿ૸ಡຊ
    w ,PUMJOελʔτϒοΫ
    w ,PUMJOΠϯΞΫγϣϯ
    w 8FC
    w ,PUMJO,PBOT
    w IUUQTLPUMJOMBOHPSHEPDTUVUPSJBMTLPBOTIUNM
    w υοτΠϯετʔϧ
    w IUUQTEPUJOTUBMMDPNMFTTPOTCBTJD@LPUMJO

    View full-size slide

  20. ίϛϡχςΟ
    w ೔ຊ,PUMJOϢʔβάϧʔϓ
    w IUUQLPUMJOMBOHKQIFSPLVBQQDPN
    w ษڧձ
    w ॳ৺ऀ޲͚ϋϯζΦϯ
    w 4XJGU,PUMJO߹ಉษڧձ
    w ΧϯϑΝϨϯε
    w ,PUMJOΧϯϑΝϨϯε Ծ
    ˠاըਐߦத

    View full-size slide

  21. ·ͱΊ
    w ,PUMJO͸ɺ+FU#SBJOT͕։ൃͨ͠+7.ݴޠ
    w ʮ+BWBΑΓ΋҆શɾ؆ܿʹʯॻ͘͜ͱΛ໨తͱ͍ͯ͠Δ
    w ੩తܕ෇͚ΦϒδΣΫτࢦ޲ݴޠ
    w /VMM҆શܕਪ࿦
    w +BWBΤϯδχΞ΍ଞ+7.ݴޠܦݧऀ͕࢝Ί΍͍͢
    w Φʔϓϯιʔε
    w .PCJMFͷଞʹ΋ɺ8FC4FSWFS4JEFͰ΋׆༂

    View full-size slide

  22. ϋϯζΦϯ
    ։ൃ؀ڥͷ४උ
    )FMMP8PSME
    جຊతͳจ๏

    View full-size slide

  23. ։ൃ؀ڥͷ४උ

    View full-size slide

  24. ։ൃ؀ڥ
    w 5SZ,PUMJO
    w ϒϥ΢βͰ࢖͑Δ։ൃ؀ڥ
    w *OUFMMJ+*%&",PUMJO1MVHJO
    w +FU#SBJOT͕ఏڙ͢Δ*%&ʢ౷߹։ൃ؀ڥʣ
    w ,PUMJO1MVHJO͸ϓϦΠϯετʔϧࡁΈ

    View full-size slide

  25. 5SZ,PUMJO
    w IUUQTUSZLPUMJOMBOHPSH

    View full-size slide

  26. *OUFMMJ+*%&"
    w l$PNNVOJUZzΛμ΢ϯϩʔυ
    w IUUQTXXXKFUCSBJOTDPNJEFBEPXOMPBE

    View full-size slide

  27. )FMMP8PSME
    w ,PUMJOͷϓϩδΣΫτΛ৽ن࡞੒͢Δ
    w ʮ$SFBUF/FX1SPKFDUʯΛબ୒

    View full-size slide

  28. )FMMP8PSME
    w ʮ,PUMJOʯʮ,PUMJO +7.
    ʯΛબ୒
    w 1SPKFDUOBNFΛʮ)FMMP8PSMEʯͱೖྗ

    View full-size slide

  29. )FMMP8PSME
    w ιʔείʔυΛ४උ͢Δ
    w ʮTSDʯΛબ୒ͯ͠ϝχϡʔΛ։͘ʢӈΫϦοΫʣ
    w /FX,PUMJO'JMF$MBTT

    View full-size slide

  30. )FMMP8PSME
    w ʮNBJOʯͱೖྗͯ͠0,ΛΫϦοΫ
    w ԼهίʔυΛೖྗ
    fun main(args: Array) {
    println("Hello World!")
    }

    View full-size slide

  31. )FMMP8PSME
    w 3VOˠ3VOʜͰίϯύΠϧ࣮ߦ
    w ࣮ߦ݁ՌΛ֬ೝ

    View full-size slide

  32. ͓ΊͰͱ͏
    ͜ΕͰ͋ͳͨ΋
    ,PUMJOΤϯδχΞ

    View full-size slide

  33. fun main(args: Array) {
    println("Hello World!")
    }

    View full-size slide

  34. fun main(args: Array) {
    println("Hello World!")
    }
    w AGVOAͰؔ਺Λఆٛ
    w ؔ਺͸ϑΝΠϧͷτοϓϨϕϧʹએݴͰ͖Δ
    w Ϋϥεͷதʹஔ͘ඞཁ͕ͳ͍

    View full-size slide

  35. w ม਺ɾҾ਺ͷܕ͸ޙஔ
    fun main(args: Array) {
    println("Hello World!")
    }

    View full-size slide

  36. fun main(args: Array) {
    println("Hello World!")
    }
    w 4ZTUFNPVUQSJOUMOͷ୅ΘΓʹQSJOUMO
    w ,PUMJOͷඪ४ϥΠϒϥϦ͸ɺ+BWBͷඪ४ϥΠϒϥϦͷ
    ϥούʔΛଟ਺ఏڙ͍ͯ͠Δ

    View full-size slide

  37. fun main(args: Array) {
    println("Hello World!")
    }
    w ηϛίϩϯແ͠

    View full-size slide

  38. ·ͱΊ
    w *OUFMMJ+*%&"Ͱ,PUMJO։ൃ
    w )FMMP8PSME͔ΒֶͿ,PUMJOͷಛ௃
    w ؔ਺ͷએݴʹ͸AGVOAΛ࢖͏
    w ؔ਺͸ϑΝΠϧͷτοϓϨϕϧʹએݴͰ͖Δ
    w Ҿ਺ม਺ͷܕ͸໊લͷޙΖͰࢦఆ͢Δ
    w ηϛίϩϯແ͠

    View full-size slide

  39. جຊతͳจ๏

    View full-size slide

  40. ม਺
    val name = "shinohara"
    val age = 27
    w +BWBͷม਺એݴͩͱɺ࢝ΊʹܕΛॻ͘ͱ͜Ζ͔Β࢝·Δ
    w ,PUMJOͰ͸ଟ͘ͷม਺એݴͰܕΛলུͰ͖Δ
    val name: String = "shinohara"
    val age: Int = 27
    w ඞཁͰ͋Ε͹ɺ໌ࣔతʹܕΛࢦఆ͢Δ͜ͱ΋Ͱ͖Δ

    View full-size slide

  41. ม਺
    w Πϛϡʔλϒϧʢෆมͳʣม਺
    w WBM WBMVFʹ༝དྷ

    w WBMͰએݴ͞Εͨม਺͸ɺҰ౓ॳظԽ͞ΕΔͱ࠶౓஋ΛׂΓ
    ౰ͯΔ͜ͱ͸Ͱ͖ͳ͍
    w +BWBʹ͓͚ΔpOBMม਺
    w ϛϡʔλϒϧʢมߋՄೳͳʣม਺
    w WBS WBSJBCMFʹ༝དྷ

    w ஋ΛมߋͰ͖Δ
    w +BWBʹ͓͚ΔpOBMͰͳ͍௨ৗͷม਺

    View full-size slide

  42. ม਺
    val age = 27
    age = 28
    var age = 27
    age = 28
    WBM͸มߋͰ͖ͳ͍
    WBS΁ͷ୅ೖ͸Մೳ

    View full-size slide

  43. ม਺
    w ϛϡʔλϒϧͳม਺Λએݴͯ͠ɺ஋Λ୅ೖͯ͠ΈΔ
    var keyword = "Good morning!"
    fun main(args: Array) {
    println(keyword)
    keyword = "Good afternoon!"
    println(keyword)
    }

    View full-size slide

  44. ม਺
    w ϛϡʔλϒϧͳม਺ΛΠϛϡʔλϒϧʢWBMʣʹม͑ͯΈΔͱɺ
    *%&্ͰίϯύΠϧΤϥʔʹͳΔ

    View full-size slide

  45. ·ͱΊ
    w ,PUMJOͰ͸ɺม਺ͷܕએݴΛলུͰ͖Δʢܕਪ࿦ʣ
    w ໌ࣔతʹॻ͘͜ͱ΋Մೳ
    w ม਺ͷछྨ
    w Πϛϡʔλϒϧʢෆมͳʣม਺ˠWBM
    w ϛϡʔλϒϧʢมߋՄೳͳʣม਺ˠWBS

    View full-size slide

  46. ৭ʑͳΦϒδΣΫτ

    View full-size slide

  47. ഑ྻ
    w ഑ྻ͸Ϋϥε"SSBZʹΑͬͯදݱ͞ΕΔ
    w ඪ४ϥΠϒϥϦؔ਺BSSBZ0GΛ࢖ͬͯΈΔ
    fun main(args: Array) {
    val colors = arrayOf("red", "green", "blue")
    println(colors[0])
    }

    View full-size slide

  48. ίϨΫγϣϯ
    w ஋ͷίϯςφͱͳΔΦϒδΣΫτΛʮίϨΫγϣϯʯͱݺͿ
    w ϦετηοτϚοϓ
    w ͜͜Ͱ͸ɺϦετΛྫʹڍ͛ͯઆ໌
    w ਺஋ͷϦετΦϒδΣΫτΛఆٛͯ͠αΠζͱ൪໨ͷཁૉΛग़ྗͯ͠ΈΔ
    fun main(args: Array) {
    val ints: List = listOf(1, 2, 3)
    println(ints.size)
    println(ints[0])
    }

    View full-size slide

  49. ίϨΫγϣϯ
    w JOUT<>ͷ஋Λมߋ͠Α͏ͱ͢ΔͱɺίϯύΠϧΤϥʔ
    w ,PUMJOͰ͸ɺίϨΫγϣϯͷϛϡʔλϒϧɾΠϛϡʔλϒϧΛ۠ผ͢Δ
    w ϛϡʔλϒϧʢมߋՄೳͳʣϦετʹ͍ͨ͠৔߹͸.VUBCMF-JTUΛ
    એݴ͢Δ

    View full-size slide

  50. ίϨΫγϣϯ
    fun main(args: Array) {
    val ints: MutableList = mutableListOf(1, 2, 3)
    println(ints[0])
    ints[0] = 4
    println(ints[0])
    }
    fun main(args: Array) {
    val ints: MutableList = mutableListOf(1, 2, 3)
    println(ints)
    ints.add(4)
    println(ints)
    }
    w .VUBCMF-JTU͸Ϧετͷ஋௥Ճ࡟আ͕Ͱ͖Δ

    View full-size slide

  51. JGFMTF
    w είΞ͕఺Ҏ্ͩͬͨΒTVDDFTTɺ఺ະຬͩͬͨΒGBJMVSFͱ
    QSJOUͯ͠ΈΔ
    fun main(args: Array) {
    val score = 80
    if (score >= 60) {
    println("success")
    } else {
    println("failure")
    }
    }

    View full-size slide

  52. JGFMTF
    w ,PUMJOͷJG͸ࣜͰ͋ΓɺจͰ͸ͳ͍
    w จͱࣜͷҧ͍
    w ࣜ͸ɺผͷࣜͷҰ෦ͱͯ͠࢖༻Ͱ͖Δ஋Λ࣋ͭ
    w จ͸ɺϒϩοΫͰғ·ΕͨτοϓϨϕϧͷཁૉͰ͋Γɺ
    ͦΕࣗ਎͸஋Λ࣋ͨͳ͍
    fun main(args: Array) {
    val score = 80
    val message = if (score >= 60) "success" else "failure"
    println(message)
    }

    View full-size slide

  53. XIFO
    w +BWBʹ͓͚ΔTXJUDIจΛڧྗʹͨࣜ͠
    w ෼ذ৚݅ʹఆ਺Ҏ֎ͷࢦఆ͕Ͱ͖Δ
    w ʮOVNCFS͕ͷͱ͖ʯͷ৚݅෼ذΛXIFOͰ࡞ͬͯΈΔ
    fun main(args: Array) {
    val number = 1
    when (number) {
    1 -> println("number is one.")
    2, 3 -> println("number is two or three.")
    else -> println("unknown.")
    }
    }

    View full-size slide

  54. XIFO
    w ෳࡶͳJGFMTFͷՄಡੑ޲্ʹ༗ޮ
    fun main(args: Array) {
    val number = 1
    if (number == 1) {
    } else if (number == 2) {
    } else if (number == 3) {
    } else if (number == 4) {
    } else if (number == 5) {
    }
    }
    fun main(args: Array) {
    val number = 1
    when (number) {
    1 -> { ... }
    2 -> { ... }
    3 -> { ... }
    4 -> { ... }
    5 -> { ... }
    }
    }

    View full-size slide

  55. GPS
    w Ϧετͷத਎Λ͢΂ͯQSJOUͯ͠ΈΔ
    fun main(args: Array) {
    val colors = listOf("red", "green", "blue")
    for (color in colors) {
    println(color)
    }
    }
    ܁Γฦ͠ՄೳͳΦϒδΣΫτͷ
    ཁૉΛॱ൪ʹऔΓग़͢

    View full-size slide

  56. GPSϨϯδ
    w Ϩϯδ
    w ൣғΛද͢ΦϒδΣΫτ
    w ʮdʯΛද͢ΦϒδΣΫτ͸ʮʯͱදݱͰ͖Δ
    w GPSͱϨϯδΛ૊Έ߹Θͤͯɺ೚ҙͷൣғʹରͯ͠ॱ൪ʹΞΫηεͰ͖Δ
    w ͔Β·Ͱͷ਺Λ͢΂ͯ଍ͯ͠QSJOUͯ͠ΈΔ
    fun main(args: Array) {
    var sum = 0
    for (i in 1..10) {
    sum += i
    }
    println(sum)
    }

    View full-size slide

  57. ·ͱΊ
    w ༷ʑͳΦϒδΣΫτ
    w ഑ྻ
    w ϦετηοτϚοϓ
    w ϛϡʔλϒϧΠϛϡʔλϒϧΛ࢖͍෼͚Δ
    w ৚݅෼ذ
    w ,PUMJOͷJG͸ࣜ
    w ෳࡶͳJGFMTF͸XIFOΛ׆༻ͯ͠ΈΔ
    w ܁Γฦ͠
    w GPSΛ࢖ͬͯ܁Γฦ͠ՄೳͳΦϒδΣΫτͷཁૉʹॱ൪ʹΞΫηεͰ͖Δ
    w Ϩϯδ YZ
    Ͱൣғࢦఆͨ͠ΦϒδΣΫτΛੜ੒ͯ͠ॱ൪ʹΞΫηεͰ͖Δ

    View full-size slide

  58. 'J[[#V[[
    w ͔Β·ͰΛϓϦϯτ͢Δ
    w ͰׂΓ੾ΕΔ਺͸ɺͦͷ਺ࣈͷ୅ΘΓʹʮ'J[[ʯͱϓϦϯτ
    w ͰׂΓ੾ΕΔ਺͸ɺͦͷ਺ࣈͷ୅ΘΓʹʮ#V[[ʯͱϓϦϯτ
    w ͱͦΕͧΕׂΓ੾ΕΔ਺͸ɺͦͷ਺ࣈͷ୅ΘΓʹʮ'J[[#V[[ʯͱϓϦϯτ

    View full-size slide

  59. fun main(args: Array) {
    for (i in 1..100) {
    when {
    i % 15 == 0 -> println("FizzBuzz")
    i % 3 == 0 -> println("Fizz")
    i % 5 == 0 -> println("Buzz")
    else -> println(i)
    }
    }
    }
    'J[[#V[[

    View full-size slide

  60. 'J[[#V[[
    fun main(args: Array) {
    (1..100).forEach { i ->
    when {
    i % 15 == 0 -> println("FizzBuzz")
    i % 3 == 0 -> println("Fizz")
    i % 5 == 0 -> println("Buzz")
    else -> println(i)
    }
    }
    }

    View full-size slide

  61. ؔ਺
    fun sum(a: Int, b: Int): Int {
    return a + b
    }

    View full-size slide

  62. ؔ਺
    fun sum(a: Int, b: Int): Int {
    return a + b
    }
    ؔ਺໊ Ҿ਺ ໭Γ஋ͷܕ
    ؔ਺ͷຊମ

    View full-size slide

  63. ؔ਺
    w ଍͠ࢉͷ݁Ռ͕ग़ྗ͞ΕΔϓϩάϥϜΛ࡞ͬͯΈΔ
    fun main(args: Array) {
    println(sum(1, 2))
    }
    fun sum(a: Int, b: Int): Int {
    return a + b
    }

    View full-size slide

  64. ͍Ζ͍Ζͳؔ਺Λ
    ࡞ͬͯΈΔ

    View full-size slide

  65. w ʮTRVBSFʯ
    w Ҿ਺ͱͯ͠༩͑ΒΕͨ੔਺Λ৐ͯ͠ฦ͢
    w ʮNBYʯ
    w Ҿ਺ͱͯ͠༩͑ΒΕͨͭͷ੔਺ͷ͏ͪɺେ͖͍ํΛฦ͢
    w ʮJT&WFOʯ
    w Ҿ਺ͱͯ͠༩͑ΒΕͨ੔਺͕ۮ਺ͷ৔߹͸USVFΛɺح਺ͷ৔߹͸GBMTFΛฦ͢
    w ʮGBDUPSJDBMʯ
    w Ҿ਺ͱͯ͠༩͑ΒΕͨ੔਺ͷ֊৐Λฦ͢
    w ྫ
    ͷ֊৐
    w ʮJT$POUBJOT5ISFFʯ
    w Ҿ਺ͱͯ͠༩͑ΒΕͨϦετʹʮʯؚ͕·ΕΔ͔Ͳ͏͔Λ#PPMFBOͰฦ͢
    ͍Ζ͍Ζͳؔ਺Λ࡞ͬͯΈΔ

    View full-size slide

  66. Ϋϥε
    class Person(val name: String)
    val person: Person = Person("shinohara")
    fun main(args: Array) {
    println(person.name) // shinohara
    }
    Ϋϥεఆٛ
    Πϯελϯεੜ੒

    View full-size slide

  67. Ϋϥε
    class Person(val name: String)
    val person: Person = Person("shinohara")
    fun main(args: Array) {
    println(person.name) // shinohara
    }
    ϓϥΠϚϦίϯετϥΫλͱҾ਺

    View full-size slide

  68. Ϋϥε
    class Person(val name: String)
    val person: Person = Person("shinohara")
    fun main(args: Array) {
    println(person.name) // shinohara
    }
    ϓϩύςΟ
    ϓϩύςΟ

    View full-size slide

  69. Ϋϥεͱϝιου
    class Person(val name: String) {
    fun introduceMyself() {
    println("I am ${name}”)
    }
    }
    val person: Person = Person("shinohara")
    fun main(args: Array) {
    person.introduceMyself() // I am shinohara
    }

    View full-size slide

  70. w Ϋϥε໊ʮ*OU1BJSʯ
    w ͭͷϓϩύςΟΛ࣋ͭ
    w pSTU*OU
    w TFDPOE*OU
    w ͭͷϝιουΛ࣋ͭ
    w TVN

    w pSTUͱTFDPOEͷ࿨Λฦ͢
    w NBY

    w pSTUͱTFDPOEͷ͏ͪେ͖͍ํΛฦ͢
    w TXBQ

    w pSTUͱTFDPOE͕ٯʹͳͬͨ*OU1BJSΦϒδΣΫτΛฦ͢
    Ϋϥεʮ*OU1BJSʯ

    View full-size slide

  71. class IntPair(val first: Int, val second: Int) {
    fun sum() = first + second
    fun max() = if (first > second) first else second
    fun swap() = IntPair(second, first)
    }
    fun main(args: Array) {
    val intPair = IntPair(2, 4)
    println("sum: " + intPair.sum())
    println("max: " + intPair.max())
    println("swapped object (first): " + intPair.swap().first)
    println("swapped object (second): " + intPair.swap().second)
    }
    Ϋϥεʮ*OU1BJSʯ

    View full-size slide

  72. ϋϯζΦϯऴྃ

    View full-size slide

  73. ࠓ೔΍Δ͜ͱ
    ,PUMJOʹ͍ͭͯ
    ϋϯζΦϯ
    ΦϦδφϧϓϩμΫτ։ൃʢ΋͘΋͘ձʣ

    View full-size slide

  74. ΦϦδφϧϓϩμΫτ։ൃ
    ʢ΋͘΋͘ձʣ

    View full-size slide

  75. ϋϯζΦϯ΋͏ͪΐͬͱ΍Γ͍ͨ
    w ,PUMJO,PBOT
    w ,PUMJOͷνϡʔτϦΞϧू
    IUUQTLPUMJOMBOHPSHEPDTUVUPSJBMTLPBOTIUNM

    View full-size slide

  76. "OESPJEΞϓϦ࡞ͬͯΈ͍ͨ
    w ,PUMJOBOE"OESPJE
    IUUQTEFWFMPQFSBOESPJEDPNLPUMJOJOEFYIUNM

    View full-size slide