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
320
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
310
新規事業のIoTプロダクトをプロトタイピングする技術 / IoT product prototyping in cookpad mart
shanonim
0
210
IoTで美味しい漬け物を作りたい v2 / make good pickles with IoT v2
shanonim
1
400
アルコールモニタリングIoT / Alcohol monitoring IoT
shanonim
0
560
Play with Android Things
shanonim
1
6.2k
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
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
1
360
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
5
210
サービスでLLMを採用したばっかりに振り回され続けたこの一年のあれやこれや
segavvy
2
490
How to be an AWS Community Builder | 君もAWS Community Builderになろう!〜2024 冬 CB募集直前対策編?!〜
coosuke
PRO
2
2.8k
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1.1k
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
170
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
110
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
140
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
270
Amazon VPC Lattice 最新アップデート紹介 - PrivateLink も似たようなアップデートあったけど違いとは
bigmuramura
0
200
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Why Our Code Smells
bkeepers
PRO
335
57k
Code Reviewing Like a Champion
maltzj
520
39k
YesSQL, Process and Tooling at Scale
rocio
169
14k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Cost Of JavaScript in 2023
addyosmani
45
7k
Navigating Team Friction
lara
183
15k
Six Lessons from altMBA
skipperchong
27
3.5k
Bash Introduction
62gerente
608
210k
BBQ
matthewcrist
85
9.4k
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