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

B074a109c8bed590e36ce7d053c0d683?s=47 shanonim
April 15, 2018

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

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

B074a109c8bed590e36ce7d053c0d683?s=128

shanonim

April 15, 2018
Tweet

Transcript

  1. ,PUMJO ॳ৺ऀ޲͚ϋϯζΦϯ  !TIBOPOJN UFSBUBJM@LU

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

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

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

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

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

  7. ,PUMJOʹ͍ͭͯ

  8. None
  9. ྲྀߦͬͯΔײ +7. "OESPJE OVMM҆શ ࠷ۙΑ͘ฉ͘ #FUUFS+BWB ৽͍͠ݴޠ αʔόʔαΠυ 4QSJOH'SBNFXPSL ໊લ͕͔Θ͍͍

    ͜ͱΓΜ ͔Θ͍͍ ੩తܕ෇͚ ΦϒδΣΫτࢦ޲ ܕਪ࿦ ͔Θ͍͍ ॳ৺ऀͰ΋Ͱ͖Δʁ J04ΞϓϦ΋࡞ΕΔ +4τϥϯείϯύΠϧ ͔Θ͍͍ Φʔϓϯιʔε
  10. None
  11. ϓϩάϥϛϯάݴޠ w ੩తܕ෇͚ݴޠ w ίϯύΠϧ࣌ʹܕͷ੔߹ੑΛݕࠪ w γεςϜͷݎ࿚ੑ޲্ w ΦϒδΣΫτࢦ޲ w

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

  13. w ܕਪ࿦ w ιʔείʔυ಺શͯͷม਺ͷํΛ໌ࣔతʹॻ͘ඞཁ͕ͳ͍ w จ຺͔Βม਺ͷํΛࣗಈతʹܾఆ͠ɺܕͷએݴΛলུ͢Δ val x = 1

    ม਺Λ੔਺ܕͰॳظԽ͍ͯ͠Δˠ*OUܕͰ͋Δͱ൑அ͞ΕΔ val x = "Hello World!" ม਺ΛจࣈྻܕͰॳظԽ͍ͯ͠Δˠ4USJOHܕͰ͋Δͱ൑அ͞ΕΔ ಛ௃
  14. 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ඇڐ༰ܕʹͳΔʣ ಛ௃
  15. w +BWBͱͷ૬ޓӡ༻ੑ w JOUFSPQFSBCMFXJUI+BWB +BWBͱ׬શʹ૬ޓӡ༻Մೳ  w ಉ͡ϓϩδΣΫτʹ+BWBͷίʔυͱ,PUMJOͷίʔυ͕ࠞࡏͰ͖Δ w ϓϩδΣΫτͷҰ෦͔Β,PUMJOԽՄೳˠಋೖ͕༰қ

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

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

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

     w 3VCZ೥ ೥  w 4DBMB೥ ೥  w ೥݄ʹਖ਼ࣜϦϦʔεʢਖ਼ࣜϦϦʔε͔Β೥ʣ
  19. ։ൃ؀ڥ w 8FC w 5SZ,PUMJO w *%& w *OUFMMJ+*%&" w

    &DMJQTF w "OESPJE4UVEJP "OESPJEΞϓϦ։ൃ༻
  20. ׆༂ͷ෼໺ w .PCJMF w "OESPJE w ,PUMJO/BUJWF w IUUQTLPUMJOMBOHPSHEPDTSFGFSFODFOBUJWFPWFSWJFXIUNM w

    8FC w ,PUMJOGPS+BWB4DSJQU w 4FSWFS4JEF w 4QSJOH'SBNFXPSL w IUUQTTQSJOHJPCMPHJOUSPEVDJOHLPUMJOTVQQPSUJOTQSJOHGSBNFXPSL
  21. ֶशํ๏ w ॻ੶ w ,PUMJOೖ໳·Ͱͷॿ૸ಡຊ w ,PUMJOελʔτϒοΫ w ,PUMJOΠϯΞΫγϣϯ w

    8FC w ,PUMJO,PBOT w IUUQTLPUMJOMBOHPSHEPDTUVUPSJBMTLPBOTIUNM w υοτΠϯετʔϧ w IUUQTEPUJOTUBMMDPNMFTTPOTCBTJD@LPUMJO
  22. ίϛϡχςΟ w ೔ຊ,PUMJOϢʔβάϧʔϓ w IUUQLPUMJOMBOHKQIFSPLVBQQDPN w ษڧձ w ॳ৺ऀ޲͚ϋϯζΦϯ w

    4XJGU,PUMJO߹ಉษڧձ w ΧϯϑΝϨϯε w ,PUMJOΧϯϑΝϨϯε Ծ ˠاըਐߦத
  23. None
  24. ·ͱΊ w ,PUMJO͸ɺ+FU#SBJOT͕։ൃͨ͠+7.ݴޠ w ʮ+BWBΑΓ΋҆શɾ؆ܿʹʯॻ͘͜ͱΛ໨తͱ͍ͯ͠Δ w ੩తܕ෇͚ΦϒδΣΫτࢦ޲ݴޠ w /VMM҆શܕਪ࿦ w

    +BWBΤϯδχΞ΍ଞ+7.ݴޠܦݧऀ͕࢝Ί΍͍͢ w Φʔϓϯιʔε w .PCJMFͷଞʹ΋ɺ8FC4FSWFS4JEFͰ΋׆༂
  25. ϋϯζΦϯ

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

  27. ։ൃ؀ڥͷ४උ

  28. ։ൃ؀ڥ w 5SZ,PUMJO w ϒϥ΢βͰ࢖͑Δ։ൃ؀ڥ w *OUFMMJ+*%&" ,PUMJO1MVHJO w +FU#SBJOT͕ఏڙ͢Δ*%&ʢ౷߹։ൃ؀ڥʣ

    w ,PUMJO1MVHJO͸ϓϦΠϯετʔϧࡁΈ
  29. 5SZ,PUMJO w IUUQTUSZLPUMJOMBOHPSH

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

  31. )FMMP8PSME

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

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

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

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

    World!") }
  36. )FMMP8PSME w 3VOˠ3VOʜͰίϯύΠϧ࣮ߦ w ࣮ߦ݁ՌΛ֬ೝ

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

  38. fun main(args: Array<String>) { println("Hello World!") }

  39. fun main(args: Array<String>) { println("Hello World!") } w AGVOAͰؔ਺Λఆٛ w

    ؔ਺͸ϑΝΠϧͷτοϓϨϕϧʹએݴͰ͖Δ w Ϋϥεͷதʹஔ͘ඞཁ͕ͳ͍
  40. w ม਺ɾҾ਺ͷܕ͸ޙஔ fun main(args: Array<String>) { println("Hello World!") }

  41. fun main(args: Array<String>) { println("Hello World!") } w 4ZTUFNPVUQSJOUMOͷ୅ΘΓʹQSJOUMO w

    ,PUMJOͷඪ४ϥΠϒϥϦ͸ɺ+BWBͷඪ४ϥΠϒϥϦͷ ϥούʔΛଟ਺ఏڙ͍ͯ͠Δ
  42. fun main(args: Array<String>) { println("Hello World!") } w ηϛίϩϯແ͠

  43. ·ͱΊ w *OUFMMJ+*%&"Ͱ,PUMJO։ൃ w )FMMP8PSME͔ΒֶͿ,PUMJOͷಛ௃ w ؔ਺ͷએݴʹ͸AGVOAΛ࢖͏ w ؔ਺͸ϑΝΠϧͷτοϓϨϕϧʹએݴͰ͖Δ w

    Ҿ਺ม਺ͷܕ͸໊લͷޙΖͰࢦఆ͢Δ w ηϛίϩϯແ͠
  44. جຊతͳจ๏

  45. ม਺

  46. ม਺ val name = "shinohara" val age = 27 w

    +BWBͷม਺એݴͩͱɺ࢝ΊʹܕΛॻ͘ͱ͜Ζ͔Β࢝·Δ w ,PUMJOͰ͸ଟ͘ͷม਺એݴͰܕΛলུͰ͖Δ val name: String = "shinohara" val age: Int = 27 w ඞཁͰ͋Ε͹ɺ໌ࣔతʹܕΛࢦఆ͢Δ͜ͱ΋Ͱ͖Δ
  47. ม਺ w Πϛϡʔλϒϧʢෆมͳʣม਺ w WBM WBMVFʹ༝དྷ  w WBMͰએݴ͞Εͨม਺͸ɺҰ౓ॳظԽ͞ΕΔͱ࠶౓஋ΛׂΓ ౰ͯΔ͜ͱ͸Ͱ͖ͳ͍

    w +BWBʹ͓͚ΔpOBMม਺ w ϛϡʔλϒϧʢมߋՄೳͳʣม਺ w WBS WBSJBCMFʹ༝དྷ  w ஋ΛมߋͰ͖Δ w +BWBʹ͓͚ΔpOBMͰͳ͍௨ৗͷม਺
  48. ม਺ val age = 27 age = 28 var age

    = 27 age = 28 WBM͸มߋͰ͖ͳ͍ WBS΁ͷ୅ೖ͸Մೳ
  49. ม਺ w ϛϡʔλϒϧͳม਺Λએݴͯ͠ɺ஋Λ୅ೖͯ͠ΈΔ var keyword = "Good morning!" fun main(args:

    Array<String>) { println(keyword) keyword = "Good afternoon!" println(keyword) }
  50. ม਺ w ϛϡʔλϒϧͳม਺ΛΠϛϡʔλϒϧʢWBMʣʹม͑ͯΈΔͱɺ *%&্ͰίϯύΠϧΤϥʔʹͳΔ

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

    ϛϡʔλϒϧʢมߋՄೳͳʣม਺ˠWBS
  52. ৭ʑͳΦϒδΣΫτ

  53. ഑ྻ w ഑ྻ͸Ϋϥε"SSBZʹΑͬͯදݱ͞ΕΔ w ඪ४ϥΠϒϥϦؔ਺BSSBZ0GΛ࢖ͬͯΈΔ fun main(args: Array<String>) { val

    colors = arrayOf("red", "green", "blue") println(colors[0]) }
  54. ίϨΫγϣϯ w ஋ͷίϯςφͱͳΔΦϒδΣΫτΛʮίϨΫγϣϯʯͱݺͿ w ϦετηοτϚοϓ w ͜͜Ͱ͸ɺϦετΛྫʹڍ͛ͯઆ໌ w ਺஋ͷϦετΦϒδΣΫτΛఆٛͯ͠αΠζͱ൪໨ͷཁૉΛग़ྗͯ͠ΈΔ fun

    main(args: Array<String>) { val ints: List<Int> = listOf<Int>(1, 2, 3) println(ints.size) println(ints[0]) }
  55. ίϨΫγϣϯ w JOUT<>ͷ஋Λมߋ͠Α͏ͱ͢ΔͱɺίϯύΠϧΤϥʔ w ,PUMJOͰ͸ɺίϨΫγϣϯͷϛϡʔλϒϧɾΠϛϡʔλϒϧΛ۠ผ͢Δ w ϛϡʔλϒϧʢมߋՄೳͳʣϦετʹ͍ͨ͠৔߹͸.VUBCMF-JTUΛ એݴ͢Δ

  56. ίϨΫγϣϯ fun main(args: Array<String>) { val ints: MutableList<Int> = mutableListOf<Int>(1,

    2, 3) println(ints[0]) ints[0] = 4 println(ints[0]) } fun main(args: Array<String>) { val ints: MutableList<Int> = mutableListOf<Int>(1, 2, 3) println(ints) ints.add(4) println(ints) } w .VUBCMF-JTU͸Ϧετͷ஋௥Ճ࡟আ͕Ͱ͖Δ
  57. ৚݅෼ذ

  58. JGFMTF w είΞ͕఺Ҏ্ͩͬͨΒTVDDFTTɺ఺ະຬͩͬͨΒGBJMVSFͱ QSJOUͯ͠ΈΔ fun main(args: Array<String>) { val score

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

    fun main(args: Array<String>) { val score = 80 val message = if (score >= 60) "success" else "failure" println(message) }
  60. XIFO w +BWBʹ͓͚ΔTXJUDIจΛڧྗʹͨࣜ͠ w ෼ذ৚݅ʹఆ਺Ҏ֎ͷࢦఆ͕Ͱ͖Δ w ʮOVNCFS͕ͷͱ͖ʯͷ৚݅෼ذΛXIFOͰ࡞ͬͯΈΔ fun main(args: Array<String>)

    { val number = 1 when (number) { 1 -> println("number is one.") 2, 3 -> println("number is two or three.") else -> println("unknown.") } }
  61. XIFO w ෳࡶͳJGFMTFͷՄಡੑ޲্ʹ༗ޮ fun main(args: Array<String>) { 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<String>) { val number = 1 when (number) { 1 -> { ... } 2 -> { ... } 3 -> { ... } 4 -> { ... } 5 -> { ... } } }
  62. ܁Γฦ͠

  63. GPS w Ϧετͷத਎Λ͢΂ͯQSJOUͯ͠ΈΔ fun main(args: Array<String>) { val colors =

    listOf("red", "green", "blue") for (color in colors) { println(color) } } ܁Γฦ͠ՄೳͳΦϒδΣΫτͷ ཁૉΛॱ൪ʹऔΓग़͢
  64. GPS Ϩϯδ w Ϩϯδ w ൣғΛද͢ΦϒδΣΫτ w ʮdʯΛද͢ΦϒδΣΫτ͸ʮʯͱදݱͰ͖Δ w GPSͱϨϯδΛ૊Έ߹Θͤͯɺ೚ҙͷൣғʹରͯ͠ॱ൪ʹΞΫηεͰ͖Δ

    w ͔Β·Ͱͷ਺Λ͢΂ͯ଍ͯ͠QSJOUͯ͠ΈΔ fun main(args: Array<String>) { var sum = 0 for (i in 1..10) { sum += i } println(sum) }
  65. ·ͱΊ w ༷ʑͳΦϒδΣΫτ w ഑ྻ w ϦετηοτϚοϓ w ϛϡʔλϒϧΠϛϡʔλϒϧΛ࢖͍෼͚Δ w

    ৚݅෼ذ w ,PUMJOͷJG͸ࣜ w ෳࡶͳJGFMTF͸XIFOΛ׆༻ͯ͠ΈΔ w ܁Γฦ͠ w GPSΛ࢖ͬͯ܁Γฦ͠ՄೳͳΦϒδΣΫτͷཁૉʹॱ൪ʹΞΫηεͰ͖Δ w Ϩϯδ YZ Ͱൣғࢦఆͨ͠ΦϒδΣΫτΛੜ੒ͯ͠ॱ൪ʹΞΫηεͰ͖Δ
  66. 'J[[#V[[

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

  68. fun main(args: Array<String>) { 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[[
  69. 'J[[#V[[ fun main(args: Array<String>) { (1..100).forEach { i -> when

    { i % 15 == 0 -> println("FizzBuzz") i % 3 == 0 -> println("Fizz") i % 5 == 0 -> println("Buzz") else -> println(i) } } }
  70. ؔ਺

  71. ؔ਺ fun sum(a: Int, b: Int): Int { return a

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

    + b } ؔ਺໊ Ҿ਺ ໭Γ஋ͷܕ ؔ਺ͷຊମ
  73. ؔ਺ w ଍͠ࢉͷ݁Ռ͕ग़ྗ͞ΕΔϓϩάϥϜΛ࡞ͬͯΈΔ fun main(args: Array<String>) { println(sum(1, 2)) }

    fun sum(a: Int, b: Int): Int { return a + b }
  74. ͍Ζ͍Ζͳؔ਺Λ ࡞ͬͯΈΔ

  75. w ʮTRVBSFʯ w Ҿ਺ͱͯ͠༩͑ΒΕͨ੔਺Λ৐ͯ͠ฦ͢ w ʮNBYʯ w Ҿ਺ͱͯ͠༩͑ΒΕͨͭͷ੔਺ͷ͏ͪɺେ͖͍ํΛฦ͢ w ʮJT&WFOʯ

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

  77. Ϋϥε class Person(val name: String) val person: Person = Person("shinohara")

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

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

    fun main(args: Array<String>) { println(person.name) // shinohara } ϓϩύςΟ ϓϩύςΟ
  80. Ϋϥεͱϝιου class Person(val name: String) { fun introduceMyself() { println("I

    am ${name}”) } } val person: Person = Person("shinohara") fun main(args: Array<String>) { person.introduceMyself() // I am shinohara }
  81. 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ʯ
  82. 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<String>) { 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ʯ
  83. ϋϯζΦϯऴྃ

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

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

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

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