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
310
新規事業のIoTプロダクトをプロトタイピングする技術 / IoT product prototyping in cookpad mart
shanonim
0
200
IoTで美味しい漬け物を作りたい v2 / make good pickles with IoT v2
shanonim
1
390
アルコールモニタリングIoT / Alcohol monitoring IoT
shanonim
0
550
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
Flutterによる 効率的なAndroid・iOS・Webアプリケーション開発の事例
recruitengineers
PRO
0
120
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
910
日経電子版のStoreKit2フルリニューアル
shimastripe
1
140
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
230
アジャイルチームがらしさを発揮するための目標づくり / Making the goal and enabling the team
kakehashi
3
150
データプロダクトの定義からはじめる、データコントラクト駆動なデータ基盤
chanyou0311
2
330
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
1
450
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
230
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.4k
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
950
OTelCol_TailSampling_and_SpanMetrics
gumamon
1
220
Featured
See All Featured
Designing Experiences People Love
moore
138
23k
Building Applications with DynamoDB
mza
90
6.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Bash Introduction
62gerente
608
210k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Adopting Sorbet at Scale
ufuk
73
9.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
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