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
370
アルコールモニタリングIoT / Alcohol monitoring IoT
shanonim
0
540
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
Oracle GoldenGate 23ai 導入Tips
oracle4engineer
PRO
1
280
分析者起点の企画を成功させた連携面の工夫
lycorptech_jp
PRO
1
260
【shownet.conf_】3Dアプローチで守るセキュリティ
shownet
PRO
0
390
【shownet.conf_】ShowNet x 宇宙ネットワーク
shownet
PRO
0
420
I tried the newly introduced certification "Applied Skills" on Microsoft Learn
mappie_kochi
0
200
Azure Verified Moduleを触って分かった注目ポイント/azure-verified-module-begin
mhrtech
1
440
LeSSはスクラムではない!?LeSSにおけるスクラムマスターの振る舞い方とは / Scrum Master Behavior in LeSS
toma_sm
0
210
Oracle Database 23ai 新機能#4 Real Application Clusters
oracle4engineer
PRO
0
160
【インフラエンジニアbooks】30分でわかる「AWS継続的セキュリティ実践ガイド」
hssh2_bin
4
1.7k
Low Latency Join Method for Distributed DBMS
yugabytejapan
0
180
Slackbot × RAG で実現する社内情報検索の最適化
howdy39
2
340
テストコードの品質を客観的な数値で担保しよう〜Mutation Testのすすめ〜
ysknsid25
12
3.3k
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Statistics for Hackers
jakevdp
796
220k
Speed Design
sergeychernyshev
22
490
GitHub's CSS Performance
jonrohan
1030
450k
KATA
mclloyd
27
13k
The Invisible Customer
myddelton
119
13k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.8k
Into the Great Unknown - MozCon
thekraken
31
1.4k
From Idea to $5000 a Month in 5 Months
shpigford
381
46k
Designing for humans not robots
tammielis
249
25k
How GitHub (no longer) Works
holman
311
140k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
92
16k
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