Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kotlin初心者向けハンズオン #3 / Kotlin Hands-on for Begin...
Search
shanonim
April 15, 2018
Technology
2
310
Kotlin初心者向けハンズオン #3 / Kotlin Hands-on for Beginners
2018.04.15
Kotlin初心者向けハンズオン #3
https://kotlin.connpass.com/event/79344/
shanonim
April 15, 2018
Tweet
Share
More Decks by shanonim
See All by shanonim
実践 Glass EE2 向けアプリ開発 / Practical Glass EE2 app development
shanonim
0
240
What's "Material You"
shanonim
0
300
新規事業のIoTプロダクトをプロトタイピングする技術 / IoT product prototyping in cookpad mart
shanonim
0
200
IoTで美味しい漬け物を作りたい v2 / make good pickles with IoT v2
shanonim
1
380
アルコールモニタリングIoT / Alcohol monitoring IoT
shanonim
0
550
Play with Android Things
shanonim
1
6.1k
Android Things Now
shanonim
1
590
UI模写のすゝめ / Encouragement of UI drawing
shanonim
3
2.2k
食卓を支える技術 ~Oisixのアプリ開発~ / App Development in Oisix
shanonim
0
1.3k
Other Decks in Technology
See All in Technology
生成AIと知識グラフの相互利用に基づく文書解析
koujikozaki
1
140
WINTICKETアプリで実現した高可用性と高速リリースを支えるエコシステム / winticket-eco-system
cyberagentdevelopers
PRO
1
190
Aurora_BlueGreenDeploymentsやってみた
tsukasa_ishimaru
1
120
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
27
12k
ガバメントクラウド単独利用方式におけるIaC活用
techniczna
3
270
【若手エンジニア応援LT会】AWSで繋がり、共に成長! ~コミュニティ活動と新人教育への挑戦~
kazushi_ohata
0
180
新卒1年目が挑む!生成AI × マルチエージェントで実現する次世代オンボーディング / operation-ai-onboarding
cyberagentdevelopers
PRO
1
160
Java x Spring Boot Warm up
kazu_kichi_67
2
490
いまならこう作りたい AWSコンテナ[本格]入門ハンズオン 〜2024年版 ハンズオンの構想〜
horsewin
9
2.1k
グローバル展開を見据えたサービスにおける機械翻訳プラクティス / dp-ai-translating
cyberagentdevelopers
PRO
1
150
2024-10-30-reInventStandby_StudyGroup_Intro
shinichirokawano
1
630
AIを駆使したゲーム開発戦略: 新設AI組織の取り組み / sge-ai-strategy
cyberagentdevelopers
PRO
1
130
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
YesSQL, Process and Tooling at Scale
rocio
167
14k
GraphQLとの向き合い方2022年版
quramy
43
13k
GitHub's CSS Performance
jonrohan
1030
460k
Six Lessons from altMBA
skipperchong
26
3.5k
Side Projects
sachag
452
42k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
The Language of Interfaces
destraynor
154
24k
Music & Morning Musume
bryan
46
6.1k
The Invisible Side of Design
smashingmag
297
50k
Transcript
,PUMJO ॳ৺ऀ͚ϋϯζΦϯ !TIBOPOJN UFSBUBJM@LU
ࣗݾհ ࣰݪ߂ޫ !TIBOPOJN ,PUMJOྺϲ݄
w ΦʔΨχοΫ৯ͷ&$αʔϏεʲ0JTJYʳΛఏڙ w 8FCJ04"OESPJE
w ,PUMJOͰ"OESPJEΞϓϦΛϑϧϦχϡʔΞϧͨ͠ w IUUQDSFBUPSTPJTJYDPKQFOUSZ w IUUQTSFDSVJUPJTJYEPUEBJDIJDPKQKPCFOHJOFFS
,PUMJOॳ৺ऀ͚ϋϯζΦϯ
ࠓΔ͜ͱ ,PUMJOʹ͍ͭͯ ϋϯζΦϯ ΦϦδφϧϓϩμΫτ։ൃʢ͘͘ձʣ
,PUMJOʹ͍ͭͯ
None
ྲྀߦͬͯΔײ +7. "OESPJE OVMM҆શ ࠷ۙΑ͘ฉ͘ #FUUFS+BWB ৽͍͠ݴޠ αʔόʔαΠυ 4QSJOH'SBNFXPSL ໊લ͕͔Θ͍͍
͜ͱΓΜ ͔Θ͍͍ ੩తܕ͚ ΦϒδΣΫτࢦ ܕਪ ͔Θ͍͍ ॳ৺ऀͰͰ͖Δʁ J04ΞϓϦ࡞ΕΔ +4τϥϯείϯύΠϧ ͔Θ͍͍ Φʔϓϯιʔε
None
ϓϩάϥϛϯάݴޠ w ੩తܕ͚ݴޠ w ίϯύΠϧ࣌ʹܕͷ߹ੑΛݕࠪ w γεςϜͷݎ࿚ੑ্ w ΦϒδΣΫτࢦ w
+7.ݴޠ
ಛ w ʰ#FUUFS+BWBʱ w +BWBΑΓ҆શͰ؆ܿʹॻ͘͜ͱ͕Ͱ͖Δݴޠ w +BWBͦͷଞ+7.ݴޠܦݧऀ͕࢝Ί͍͢ݴޠ
w ܕਪ w ιʔείʔυશͯͷมͷํΛ໌ࣔతʹॻ͘ඞཁ͕ͳ͍ w จ຺͔ΒมͷํΛࣗಈతʹܾఆ͠ɺܕͷએݴΛলུ͢Δ val x = 1
มΛܕͰॳظԽ͍ͯ͠Δˠ*OUܕͰ͋Δͱஅ͞ΕΔ val x = "Hello World!" มΛจࣈྻܕͰॳظԽ͍ͯ͠Δˠ4USJOHܕͰ͋Δͱஅ͞ΕΔ ಛ
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ඇڐ༰ܕʹͳΔʣ ಛ
w +BWBͱͷ૬ޓӡ༻ੑ w JOUFSPQFSBCMFXJUI+BWB +BWBͱશʹ૬ޓӡ༻Մೳ w ಉ͡ϓϩδΣΫτʹ+BWBͷίʔυͱ,PUMJOͷίʔυ͕ࠞࡏͰ͖Δ w ϓϩδΣΫτͷҰ෦͔Β,PUMJOԽՄೳˠಋೖ͕༰қ
ಛ
։ൃݩ w +FU#SBJOT w *OUFMMJ+*%&"ͷ։ൃݩ w "OESPJEͷ։ൃݴޠͱͯ͠ਖ਼ࣜ࠾༻ w IUUQTEFWFMPQFSBOESPJEDPNLPUMJOJOEFYIUNM
໊લͷ༝དྷ w ίτϦϯౡ w ʬ,PUMJOʗЮѓїѐэђʭϩγΞ࿈෦ɺϑΟϯϥϯυԞʹ͋Δౡ w ౬͔͠ͷ͔ΜΛද͢ϑΟϯϥϯυޠˠ,PUMJO
ϦϦʔε w ৽͍͠ݴޠ w ݄ʹ,PUMJOϓϩδΣΫτΛΞφϯε w 1ZUIPO
w 3VCZ w 4DBMB w ݄ʹਖ਼ࣜϦϦʔεʢਖ਼ࣜϦϦʔε͔Βʣ
։ൃڥ w 8FC w 5SZ,PUMJO w *%& w *OUFMMJ+*%&" w
&DMJQTF w "OESPJE4UVEJP "OESPJEΞϓϦ։ൃ༻
׆༂ͷ w .PCJMF w "OESPJE w ,PUMJO/BUJWF w IUUQTLPUMJOMBOHPSHEPDTSFGFSFODFOBUJWFPWFSWJFXIUNM w
8FC w ,PUMJOGPS+BWB4DSJQU w 4FSWFS4JEF w 4QSJOH'SBNFXPSL w IUUQTTQSJOHJPCMPHJOUSPEVDJOHLPUMJOTVQQPSUJOTQSJOHGSBNFXPSL
ֶशํ๏ w ॻ੶ w ,PUMJOೖ·Ͱͷॿಡຊ w ,PUMJOελʔτϒοΫ w ,PUMJOΠϯΞΫγϣϯ w
8FC w ,PUMJO,PBOT w IUUQTLPUMJOMBOHPSHEPDTUVUPSJBMTLPBOTIUNM w υοτΠϯετʔϧ w IUUQTEPUJOTUBMMDPNMFTTPOTCBTJD@LPUMJO
ίϛϡχςΟ w ຊ,PUMJOϢʔβάϧʔϓ w IUUQLPUMJOMBOHKQIFSPLVBQQDPN w ษڧձ w ॳ৺ऀ͚ϋϯζΦϯ w
4XJGU,PUMJO߹ಉษڧձ w ΧϯϑΝϨϯε w ,PUMJOΧϯϑΝϨϯε Ծ ˠاըਐߦத
None
·ͱΊ w ,PUMJOɺ+FU#SBJOT͕։ൃͨ͠+7.ݴޠ w ʮ+BWBΑΓ҆શɾ؆ܿʹʯॻ͘͜ͱΛతͱ͍ͯ͠Δ w ੩తܕ͚ΦϒδΣΫτࢦݴޠ w /VMM҆શܕਪ w
+BWBΤϯδχΞଞ+7.ݴޠܦݧऀ͕࢝Ί͍͢ w Φʔϓϯιʔε w .PCJMFͷଞʹɺ8FC4FSWFS4JEFͰ׆༂
ϋϯζΦϯ
ϋϯζΦϯ ։ൃڥͷ४උ )FMMP8PSME جຊతͳจ๏
։ൃڥͷ४උ
։ൃڥ w 5SZ,PUMJO w ϒϥβͰ͑Δ։ൃڥ w *OUFMMJ+*%&" ,PUMJO1MVHJO w +FU#SBJOT͕ఏڙ͢Δ*%&ʢ౷߹։ൃڥʣ
w ,PUMJO1MVHJOϓϦΠϯετʔϧࡁΈ
5SZ,PUMJO w IUUQTUSZLPUMJOMBOHPSH
*OUFMMJ+*%&" w l$PNNVOJUZzΛμϯϩʔυ w IUUQTXXXKFUCSBJOTDPNJEFBEPXOMPBE
)FMMP8PSME
)FMMP8PSME w ,PUMJOͷϓϩδΣΫτΛ৽ن࡞͢Δ w ʮ$SFBUF/FX1SPKFDUʯΛબ
)FMMP8PSME w ʮ,PUMJOʯʮ,PUMJO +7. ʯΛબ w 1SPKFDUOBNFΛʮ)FMMP8PSMEʯͱೖྗ
)FMMP8PSME w ιʔείʔυΛ४උ͢Δ w ʮTSDʯΛબͯ͠ϝχϡʔΛ։͘ʢӈΫϦοΫʣ w /FX,PUMJO'JMF$MBTT
)FMMP8PSME w ʮNBJOʯͱೖྗͯ͠0,ΛΫϦοΫ w ԼهίʔυΛೖྗ fun main(args: Array<String>) { println("Hello
World!") }
)FMMP8PSME w 3VOˠ3VOʜͰίϯύΠϧ࣮ߦ w ࣮ߦ݁ՌΛ֬ೝ
͓ΊͰͱ͏ ͜ΕͰ͋ͳͨ ,PUMJOΤϯδχΞ
fun main(args: Array<String>) { println("Hello World!") }
fun main(args: Array<String>) { println("Hello World!") } w AGVOAͰؔΛఆٛ w
ؔϑΝΠϧͷτοϓϨϕϧʹએݴͰ͖Δ w Ϋϥεͷதʹஔ͘ඞཁ͕ͳ͍
w มɾҾͷܕޙஔ fun main(args: Array<String>) { println("Hello World!") }
fun main(args: Array<String>) { println("Hello World!") } w 4ZTUFNPVUQSJOUMOͷΘΓʹQSJOUMO w
,PUMJOͷඪ४ϥΠϒϥϦɺ+BWBͷඪ४ϥΠϒϥϦͷ ϥούʔΛଟఏڙ͍ͯ͠Δ
fun main(args: Array<String>) { println("Hello World!") } w ηϛίϩϯແ͠
·ͱΊ w *OUFMMJ+*%&"Ͱ,PUMJO։ൃ w )FMMP8PSME͔ΒֶͿ,PUMJOͷಛ w ؔͷએݴʹAGVOAΛ͏ w ؔϑΝΠϧͷτοϓϨϕϧʹએݴͰ͖Δ w
Ҿมͷܕ໊લͷޙΖͰࢦఆ͢Δ w ηϛίϩϯແ͠
جຊతͳจ๏
ม
ม val name = "shinohara" val age = 27 w
+BWBͷมએݴͩͱɺ࢝ΊʹܕΛॻ͘ͱ͜Ζ͔Β࢝·Δ w ,PUMJOͰଟ͘ͷมએݴͰܕΛলུͰ͖Δ val name: String = "shinohara" val age: Int = 27 w ඞཁͰ͋Εɺ໌ࣔతʹܕΛࢦఆ͢Δ͜ͱͰ͖Δ
ม w Πϛϡʔλϒϧʢෆมͳʣม w WBM WBMVFʹ༝དྷ w WBMͰએݴ͞ΕͨมɺҰॳظԽ͞ΕΔͱ࠶ΛׂΓ ͯΔ͜ͱͰ͖ͳ͍
w +BWBʹ͓͚ΔpOBMม w ϛϡʔλϒϧʢมߋՄೳͳʣม w WBS WBSJBCMFʹ༝དྷ w ΛมߋͰ͖Δ w +BWBʹ͓͚ΔpOBMͰͳ͍௨ৗͷม
ม val age = 27 age = 28 var age
= 27 age = 28 WBMมߋͰ͖ͳ͍ WBSͷೖՄೳ
ม w ϛϡʔλϒϧͳมΛએݴͯ͠ɺΛೖͯ͠ΈΔ var keyword = "Good morning!" fun main(args:
Array<String>) { println(keyword) keyword = "Good afternoon!" println(keyword) }
ม w ϛϡʔλϒϧͳมΛΠϛϡʔλϒϧʢWBMʣʹม͑ͯΈΔͱɺ *%&্ͰίϯύΠϧΤϥʔʹͳΔ
·ͱΊ w ,PUMJOͰɺมͷܕએݴΛলུͰ͖Δʢܕਪʣ w ໌ࣔతʹॻ͘͜ͱՄೳ w มͷछྨ w ΠϛϡʔλϒϧʢෆมͳʣมˠWBM w
ϛϡʔλϒϧʢมߋՄೳͳʣมˠWBS
৭ʑͳΦϒδΣΫτ
ྻ w ྻΫϥε"SSBZʹΑͬͯදݱ͞ΕΔ w ඪ४ϥΠϒϥϦؔBSSBZ0GΛͬͯΈΔ fun main(args: Array<String>) { val
colors = arrayOf("red", "green", "blue") println(colors[0]) }
ίϨΫγϣϯ w ͷίϯςφͱͳΔΦϒδΣΫτΛʮίϨΫγϣϯʯͱݺͿ w ϦετηοτϚοϓ w ͜͜ͰɺϦετΛྫʹڍ͛ͯઆ໌ w ͷϦετΦϒδΣΫτΛఆٛͯ͠αΠζͱ൪ͷཁૉΛग़ྗͯ͠ΈΔ fun
main(args: Array<String>) { val ints: List<Int> = listOf<Int>(1, 2, 3) println(ints.size) println(ints[0]) }
ίϨΫγϣϯ w JOUT<>ͷΛมߋ͠Α͏ͱ͢ΔͱɺίϯύΠϧΤϥʔ w ,PUMJOͰɺίϨΫγϣϯͷϛϡʔλϒϧɾΠϛϡʔλϒϧΛ۠ผ͢Δ w ϛϡʔλϒϧʢมߋՄೳͳʣϦετʹ͍ͨ͠߹.VUBCMF-JTUΛ એݴ͢Δ
ίϨΫγϣϯ 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ϦετͷՃআ͕Ͱ͖Δ
݅ذ
JGFMTF w είΞ͕Ҏ্ͩͬͨΒTVDDFTTɺະຬͩͬͨΒGBJMVSFͱ QSJOUͯ͠ΈΔ fun main(args: Array<String>) { val score
= 80 if (score >= 60) { println("success") } else { println("failure") } }
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) }
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.") } }
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 -> { ... } } }
܁Γฦ͠
GPS w ϦετͷதΛͯ͢QSJOUͯ͠ΈΔ fun main(args: Array<String>) { val colors =
listOf("red", "green", "blue") for (color in colors) { println(color) } } ܁Γฦ͠ՄೳͳΦϒδΣΫτͷ ཁૉΛॱ൪ʹऔΓग़͢
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) }
·ͱΊ w ༷ʑͳΦϒδΣΫτ w ྻ w ϦετηοτϚοϓ w ϛϡʔλϒϧΠϛϡʔλϒϧΛ͍͚Δ w
݅ذ w ,PUMJOͷJGࣜ w ෳࡶͳJGFMTFXIFOΛ׆༻ͯ͠ΈΔ w ܁Γฦ͠ w GPSΛͬͯ܁Γฦ͠ՄೳͳΦϒδΣΫτͷཁૉʹॱ൪ʹΞΫηεͰ͖Δ w Ϩϯδ YZ Ͱൣғࢦఆͨ͠ΦϒδΣΫτΛੜͯ͠ॱ൪ʹΞΫηεͰ͖Δ
'J[[#V[[
'J[[#V[[ w ͔Β·ͰΛϓϦϯτ͢Δ w ͰׂΓΕΔɺͦͷࣈͷΘΓʹʮ'J[[ʯͱϓϦϯτ w ͰׂΓΕΔɺͦͷࣈͷΘΓʹʮ#V[[ʯͱϓϦϯτ w ͱͦΕͧΕׂΓΕΔɺͦͷࣈͷΘΓʹʮ'J[[#V[[ʯͱϓϦϯτ
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[[
'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) } } }
ؔ
ؔ fun sum(a: Int, b: Int): Int { return a
+ b }
ؔ fun sum(a: Int, b: Int): Int { return a
+ b } ໊ؔ Ҿ Γͷܕ ؔͷຊମ
ؔ w ͠ࢉͷ݁Ռ͕ग़ྗ͞ΕΔϓϩάϥϜΛ࡞ͬͯΈΔ fun main(args: Array<String>) { println(sum(1, 2)) }
fun sum(a: Int, b: Int): Int { return a + b }
͍Ζ͍ΖͳؔΛ ࡞ͬͯΈΔ
w ʮTRVBSFʯ w Ҿͱͯ͠༩͑ΒΕͨΛͯ͠ฦ͢ w ʮNBYʯ w Ҿͱͯ͠༩͑ΒΕͨͭͷͷ͏ͪɺେ͖͍ํΛฦ͢ w ʮJT&WFOʯ
w Ҿͱͯ͠༩͑ΒΕ͕ͨۮͷ߹USVFΛɺحͷ߹GBMTFΛฦ͢ w ʮGBDUPSJDBMʯ w Ҿͱͯ͠༩͑ΒΕͨͷ֊Λฦ͢ w ྫ ͷ֊ w ʮJT$POUBJOT5ISFFʯ w Ҿͱͯ͠༩͑ΒΕͨϦετʹʮʯؚ͕·ΕΔ͔Ͳ͏͔Λ#PPMFBOͰฦ͢ ͍Ζ͍ΖͳؔΛ࡞ͬͯΈΔ
Ϋϥε
Ϋϥε class Person(val name: String) val person: Person = Person("shinohara")
fun main(args: Array<String>) { println(person.name) // shinohara } Ϋϥεఆٛ Πϯελϯεੜ
Ϋϥε class Person(val name: String) val person: Person = Person("shinohara")
fun main(args: Array<String>) { println(person.name) // shinohara } ϓϥΠϚϦίϯετϥΫλͱҾ
Ϋϥε class Person(val name: String) val person: Person = Person("shinohara")
fun main(args: Array<String>) { println(person.name) // shinohara } ϓϩύςΟ ϓϩύςΟ
Ϋϥεͱϝιου 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 }
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ʯ
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ʯ
ϋϯζΦϯऴྃ
ࠓΔ͜ͱ ,PUMJOʹ͍ͭͯ ϋϯζΦϯ ΦϦδφϧϓϩμΫτ։ൃʢ͘͘ձʣ
ΦϦδφϧϓϩμΫτ։ൃ ʢ͘͘ձʣ
ϋϯζΦϯ͏ͪΐͬͱΓ͍ͨ w ,PUMJO,PBOT w ,PUMJOͷνϡʔτϦΞϧू IUUQTLPUMJOMBOHPSHEPDTUVUPSJBMTLPBOTIUNM
"OESPJEΞϓϦ࡞ͬͯΈ͍ͨ w ,PUMJOBOE"OESPJE IUUQTEFWFMPQFSBOESPJEDPNLPUMJOJOEFYIUNM