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
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
220
Qiita埋め込み用スライド
naoki_0531
0
860
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
260
20241220_S3 tablesの使い方を検証してみた
handy
3
360
Storage Browser for Amazon S3
miu_crescent
1
140
Snykで始めるセキュリティ担当者とSREと開発者が楽になる脆弱性対応 / Getting started with Snyk Vulnerability Response
yamaguchitk333
2
180
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
220
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
470
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
210
Postman と API セキュリティ / Postman and API Security
yokawasa
0
200
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
170
第3回Snowflake女子会_LT登壇資料(合成データ)_Taro_CCCMK
tarotaro0129
0
180
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Statistics for Hackers
jakevdp
796
220k
Faster Mobile Websites
deanohume
305
30k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Designing for Performance
lara
604
68k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Code Reviewing Like a Champion
maltzj
520
39k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Building Adaptive Systems
keathley
38
2.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Making the Leap to Tech Lead
cromwellryan
133
9k
Fireside Chat
paigeccino
34
3.1k
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