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
Watashi ni Kotlin ga maiorita
Search
きりみん
March 19, 2019
Programming
0
490
Watashi ni Kotlin ga maiorita
きりみん
March 19, 2019
Tweet
Share
More Decks by きりみん
See All by きりみん
AndroidエンジニアがRailsにチャレンジしてる理由
kirimin
1
1.5k
What are AtCoder and competitive programming
kirimin
0
9.9k
バーチャル男声幼女プログラマーとして活動した1年間の振り返り
kirimin
0
1k
アプリエンジニアでも神絵師になりたい!
kirimin
4
5.3k
NEMのAPIとモザイクであそぼう
kirimin
0
360
はじめようきれいなコード
kirimin
8
3k
Material Components for Android触ってみる
kirimin
7
1.9k
[社内LT]あたらしいMaterial Design
kirimin
1
1.7k
Hello-kirimin-chan
kirimin
0
130
Other Decks in Programming
See All in Programming
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
CSC305 Lecture 25
javiergs
PRO
0
130
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
150
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
530
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
103 Early Hints
sugi_0000
1
220
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
130
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
350
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Automating Front-end Workflow
addyosmani
1366
200k
Being A Developer After 40
akosma
87
590k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Facilitating Awesome Meetings
lara
50
6.1k
The Invisible Side of Design
smashingmag
298
50k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
KATA
mclloyd
29
14k
Agile that works and the tools we love
rasmusluckow
328
21k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Writing Fast Ruby
sferik
628
61k
Transcript
ࢲʹKotlin͕͍߱Γͨ -AndroidͰͷKotlinҠߦΛݟ͖ͯͨࢹ͔ΒͷKotlin- in ΦλΫ͕KotlinΛ͏ϥΠτχϯάτʔΫΠϕϯτ @kirimin
ࣗݾհ • @kirimin • AndroidΤϯδχΞ • ݱࡏKotlinͰAndroid։ൃ • Kotlinྺ5͘Β͍ •
ۀͰJava͔ΒKotlinҠߦܦݧ͋Γ
͖ΓΈΜͪΌΜ • όʔνϟϧ༮ঁϓϩάϥϚʔ͖ΓΈΜͪΌ ΜͷϚωʔδϟʔͰ͢ɻ • ͍ΘΏΔVTuberɻ • ϓϩάϥϛϯάΤϯδχΞʹ͍ͭͯͷಈ ըΛߘͨ͠ΓϥΠϒίʔσΟϯά৴Λ ͨ͠Γͯ͠·͢ɻ
• νϟϯωϧొΑΖ͘͠Ͷʂ
ٕज़ॻయͰຊΛग़͠·͢(એ) • ϑϦʔϥϯεͷݟΛ ·ͱΊͨຊͱɺ͖ΓΈ ΜͪΌΜͷϑΝϯϒο Ϋ • ٕज़ॻయ64/14ʂ • ങ͍ʹ͖͍ͯͩ͘͞ʂ
Kotlinͱࢲ • ·ͩKotlinͷ໊ ͕΄ͱΜͲͳ͔ͬ ͨ2015ॳ಄͔ ΒKotlinਪ͠ • ΅͕͘ॳΊͯ Kotlinʹग़ձͬͨ ͷπΠʔτ
Kotlinͱࢲ • झຯͷΞϓϦΛKotlinʹϑϧॻ͖͑͢Δ (2015) • ࣄͰKotlinҠߦΛܦݧ(2017) • ࠓϑϧKotlinͷϓϩδΣΫτͰ։ൃ(2018)
Javaͱൺֱͨ͠Kotlinͷར
Kotlinͷجૅ(ͬ͘͟Γ) • JVMͰಈ͘Javaશޓݴޠ • ੜ࢈ੑͱཧղ͢͠͞ɺಋೖͷ͢͠͞Λҙࣝͨ͠ݱ࣮ࢤͷݴޠ • ؔܕͷΤοηϯεϞμϯͳݴޠ༷Λ࠾༻ͨ͠Alt Java • Nullڐ༰ܕͱNullඇڐ༰ܕ
• valʹΑΔఆએݴ • JavaΑΓؾܰʹ͔ͭ͑ΔศརͳϦετૢ࡞ؔ
JVMͰಈ͘Javaશޓݴޠ • KotlinͷιʔείʔυJavaόΠτίʔυʹม͞ΕΔ • ͭ·Γ࠷ऴతʹJavaʹͳΔ • JavaͷΫϥεϥΠϒϥϦ͕ී௨ʹ͑Δ • JavaϓϩδΣΫτͰڞଘՄೳ •
ٯʹKotlinͰॻ͍ͨίʔυΛJava͔Βݺͼग़͢ޓੑ༻ҙ ͞Ε͍ͯΔ
ੜ࢈ੑͱཧղ͢͠͞ɺಋೖͷɹɹ ͢͠͞Λҙࣝͨ͠ݱ࣮ࢤͷݴޠ • Kotlinಋೖͷֶ͢͠͞शίετͷ͕͞ڧΈ • Ϟμϯ͚ͩͲγϯϓϧͳݴޠ༷ • ࠷৽ͷJavaܦݧऀSwiftܦݧऀͳΒΩϟονΞοϓ͘͠ͳ͍ • ScalaClojureͳͲʹର͢Δେ͖ͳڧΈ
• GradleʹΑΔϏϧυγεςϜ • IntelliJͷެࣜαϙʔτ
ؔܕͷΤοηϯεϞμϯͳ ݴޠ༷Λ࠾༻ͨ͠Alt Java • ߴ֊ؔ(ؔΛड͚औΔؔ)Πϛϡʔλϒϧ ͳͲؔݴޠతͳΤοηϯεΛऔΓೖΕ͍ͯΔ • Java࠷ۙϥϜμࣜStreamɺOptionalɺϥ ϜμࣜͳͲؔܕతͳϞμϯͳݴޠ༷ΛऔΓ ೖΕ͍ͯΔ͕ɺKotlinݴޠϨϕϧͰαϙʔτ͞
Ε͓ͯΓɺΑΓચ࿅͞Ε͍ͯΔ
Nullڐ༰ܕͱNullඇڐ༰ܕ • KotlinͰมجຊnullΛڐ༰͠ͳ͍ɻ • nullΛڐ༰͢Δ߹໌ࣔతʹ?Λ͚ܕએݴ ͢Δඞཁ͕͋Δ • JavaͷOptionalͱಉ͡ߟ͑ํ͕ͩɺͪ͜Β ݴޠ༷ͱͯ͠αϙʔτ
Nullڐ༰ܕͱNullඇڐ༰ܕ var hoge: String = null // ίϯύΠϧΤϥʔ var hoge:
String = "hoge" hoge = null // ίϯύΠϧΤϥʔ -------------------------------------------- var fuga: String? = null // OK var fuga: String? = "fuga" fuga = null // OK
NullΛѻ͏ͨΊͷศརͳؔ var hoge: String? = "hoge" hoge.size // ίϯύΠϧΤϥʔ hoge?.size
// hoge͕nullͳΒ࣮ߦ͞Εͳ͍ hoge?.size ?: return // hoge͕nullͳΒreturn val size = hoge?.size ?: 0 // hoge͕nullͳΒ0Λೖ hoge?.let { // hoge͕nullͳΒ࣮ߦ͞Εͳ͍ println(it.size) } hoge.isNullOrEmpty() // nullۭ͘͠จࣈͳΒtrue
valએݴͱvarએݴ • valͰએݴͨ͠มෆม(ఆ)ʹͳΔ • varՄม • KotlinͰग़དྷΔ͚ͩvalΛ͏จԽ
valએݴͱvarએݴ val hoge: String = "hoge" hoge = "fuga" //
ίϯύΠϧΤϥʔ -------------------------------------------- var hoge: String = "hoge" hoge = "fuga" // OK
JavaΑΓؾܰʹ͔ͭ͑Δศརͳ Ϧετૢ࡞ؔ • KotlinͷCollectionΠϯλʔϑΣʔεʹmap filterͱ͍ͬͨͨ͘͞Μͷؔܕతͳศརϝ ιου͕ఆٛ͞Ε͍ͯΔ • JavaͷStreamͷΑ͏ͳͷ͕ͩɺΑΓؾܰʹ forจͳͲͷΘΓʹ͑Δ
JavaΑΓؾܰʹ͔ͭ͑Δศརͳ Ϧετૢ࡞ؔ val list = listof("a", "bb", "ccc") val sizeList
= list.map { str -> str.size } // sizeList = { 1, 2, 3 } val filteredList = list.filter { str -> str != "bb" } // filteredList = { "a", "ccc" }
Java͔ΒKotlinͷҠߦ
Java͔ΒKotlinͷҠߦ • KotlinͱJavaڞੜͰ͖Δ • 1Ϋϥε͔ΒҠߦΛ࢝ΊΒΕΔ • (࠶)JavaͷϥΠϒϥϦϑϨʔϜϫʔΫجຊKotlin Ͱ͑Δ • IntelliJʹϑΝΠϧΛJava͔ΒKotlinʹࣗಈมͯ͠
͘ΕΔػೳ͕͋Δ
Java͔ΒKotlinҠߦͯ͠ਏ͔ͬ ͨ • AndroidͰ΄ͱΜͲฉ͍ͨ͜ͱ͕ͳ͍ • ֶशίετ͘Javaͱൺϋʔυϧ͕ߴ͍ͱ͍͏ ͜ͱ͋·Γͳ͍ • KotlinͱJava͕ڞଘ͍ͯ͠ΔϓϩδΣΫτͨ͘͞ Μ͋Δ
• Ή͠ΖҰKotlinʹ׳ΕΔͱJavaʹΕͳ͘ͳΔ
·ͱΊ • Kotlinݱ࣮ࢤָ͔͍ͭ͠ݴޠ • AndroidͷੈքͰKotlinҠߦͷ͍͍͢͝ ͰਐΜͰ͍Δ • όοΫΤϯυͷੈքͰKotlin͕ελϯμʔυ ʹͳΔϙςϯγϟϧଟ͍ʹ͋Δͱࢥ͍ͬͯΔ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ