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
Step up Kotlin
Search
Paraya
July 13, 2017
Programming
0
66
Step up Kotlin
Paraya
July 13, 2017
Tweet
Share
More Decks by Paraya
See All by Paraya
J2K failure story : UNIT
paraya3636
0
69
J2Kコンバータをカスタマイズする ver: 5min
paraya3636
0
1.7k
J2Kコンバータをカスタマイズする
paraya3636
1
2.1k
命名おじさん
paraya3636
1
130
DDD失敗談
paraya3636
0
100
Other Decks in Programming
See All in Programming
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
130
GitHubで育つ コラボレーション文化 : ニフティでのインナーソース挑戦事例 - 2024-12-16 GitHub Universe 2024 Recap in ZOZO
niftycorp
PRO
0
730
バグを見つけた?それAppleに直してもらおう!
uetyo
0
200
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
2
510
為你自己學 Python
eddie
0
480
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
570
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
390
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
210
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
8
1.7k
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
350
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
180
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
350
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Mobile First: as difficult as doing things right
swwweet
222
9k
What's in a price? How to price your products and services
michaelherold
244
12k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
The Cost Of JavaScript in 2023
addyosmani
46
7k
A Philosophy of Restraint
colly
203
16k
Being A Developer After 40
akosma
89
590k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
830
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Transcript
Step up Kotlin! by miura(Paraya)
ࣗݾհ ϓϥοτϑΥʔϜ - Android Java 2 - iOS 3 -
Android Kotlin 1 ※New! ͦͷଞ - DDD 2
એ
Step up Kotlin!
KotlinΛ࢝ΊΔ্Ͱ৭ʑΈ ͕͋Δͱࢥ͍·͢ɻ
ݟ׳Εͳ͍ίʔυ… letͬͯԿ… ʁͬͯԿ… ͦͦͲ͏ͬͯಈ͍ͯΔ ͷ͔͔Βͳͯ͘ෆ҆
ͰKotlinΛ࢝ΊΔ্ͰɺͲ͏ ׳Ε͍ͯ͘ͷ͕͍͍ͩΖ͏͔
Javaख़࿅ऀ͕KotlinʹͲ͏׳Εͯ ͍͔͘ͷεςοϓΞοϓΛհ͠ ·͢
࣍ - Kotlinͷհ - ॳ৺ऀ͚~JavaͬΆ͘KotlinΛॻ͘~ - ࣍ͷεςοϓ~Androidʹ༗༻ͳॴΛKotlin Β͘͠ॻ͘~
Kotlinͱ KotlinҎԼͷϓϥοτϑΥʔϜ্Ͱಈ͖·͢ɻ - Kotlin for JVM - Kotlin for javascript
- Kotlin for Native(ϕʔλ൛ɻMacɺWindowsͰ ಈ͘Β͍͠)
Kotlinͱ ࠓͷͱ͜ΖJVMͷAndroidɺSpringͰͷ࠾༻ࣄ ྫΛଟ͘ฉ͖·͢ɻ ຊൃදͰJVMͷதͰAndroid͚ͷΛϝ ΠϯͰɻ
Kotlinͷྑ͍ͱ͜Ζ Null҆શͱ͔finalͱ͔ϓϩύςΟͱ͔ry ͱΓ͋͑ͣKotlinͰॻ͍͓͚ͯɺJavaͰॻ͘ ΑΓஈ্ͷ࣭ʹͳΔ͘Β͍ͷϙςϯγϟ ϧ͋Δɻ
KotlinͬͯͲ͏ಈ͍ͯΔͷʁ KotlinͰॻ͘ͱϏϧυ࣌ʹJavaͷίʔυʹม ͞Ε͍ͯ·͢ɻ
KotlinͬͯͲ͏ಈ͍ͯΔͷʁ // StringͷnameΛએݴ var name : String? name?.toInt() // Javaมޙͷίʔυ
if (name != null) { name.toInt(); } OVMMνΣοΫ͕ࣗಈੜ͞ΕΔ
࠷ऴతʹJavaͱͯ͠ಈ͘ KotlinͰॻ͍ͯ݁ہJavaͱͯ͠ಈ͘ɻ KotlinJavaͷ໘ͳ෦Λٵऩͯ͠ΑΓϕ λʔͳJavaίʔυΛੜ͢Δɻ
ॳ৺ऀ͚ ~KotlinΛJavaΆ͘ॻ͘~
KotlinΛJavaΆ͘ॻ͘ class KotlinUser(val userId: String) ϓϥΠϚϦίϯετϥΫλ ΫϥεఆٛͱҰॹʹҾPSมఆ ٛͰ͖Δ
ϓϥΠϚϦίϯετϥΫλͱ ͔Α͘Θ͔Μͳ͍ͳ
ϓϥΠϚϦίϯετϥΫλΛ Θͳ͍ class KotlinUser { val userId: String constructor(userId: String)
{ this.userId = userId } } αϒίϯετϥΫλͰॳظԽ Ϗϧυ௨Γ·͢ ˞XBSOJOHग़·͢
KotlinΛJavaΆ͘ॻ͘ fun function(text: String?) { text?.let { it.toInt() } }
/VMMBCMFUZQF /VMMBCMFUZQFΛࢀর͢Δࡍ MFU Ͱ/PO/VMMUZQFͱͯ͠ࢀর͢Δ ඞཁ͕͋Δ
?.letͱ͔Α͘Θ͔Μͳ͍ͳ
?.letΛΘͳ͍ fun function(text: String?) { if (text != null) {
text.toInt() } } /VMMBCMFUZQFΛࢀর͢Δࡍ OVMMͰͳ͍จ຺Ͱ͋Ε0,
·ͱΊ - JavaͬΆ͘ॻ͍ͯେৎ - KotlinΒ͠͞Λແཧʹٻ͠ͳͯ͘ NullSafetyͳͲͷKotlinͷओͳԸܙेड͚ ΒΕ·͢ - ؾܰʹKotlinΛॻ͍ͯΈΔ͜ͱ͕େࣄʂ
࣍ͷεςοϓ ~Androidʹ༗༻ͳॴΛ KotlinΒ͘͠ॻ͘~
lazy private View view; View getView() { if (this.view ==
null) { return View.inflate(context, R.layout.view_top, null); } else { return this.view } }
lazy private View view; View getView() { if (this.view ==
null) { return LayoutInflater.from(context).inflate(R.layout.view_top, null); } else { return this.view } } private val view by lazy { LayoutInflater.from(context).inflate(R.layout.view_top, null); } MB[ZΛ༻͍Δ͜ͱͰɺϓϩύςΟࢀর࣌ʹॳظԽ͞Ε͍ͯ ͳ͍߹͚ͩॲཧΛߦ͏ͱ͍͏͜ͱ͕Ͱ͖Δ
apply Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType(“image/*”); // ͜͜ͰԿ͔͠Βͷॲཧ context.startActivity(intent);
͜͜ͷจ຺ͰJOUFOUॳظԽࡁΈͷ ͷ͕΄͍͠ɻ ͨͩϝιουԽ͢Δʹίετ͕ߴ͍ʜ
apply val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI).apply { type = "image/*"
} // ͜͜ͰԿ͔͠Βͷॲཧ context.startActivity(intent) BQQMZΛར༻͢Δ͜ͱͰจ຺্ॳظԽࡁ ΈJOUFOUΛར༻Ͱ͖Δ
lateinit class View : RelativeLayout { private var name: String?
= null // nullͰॳظԽ͠ͳ͍ͱΤϥʔ fun initView(name: String) { this.name = name } } ຊOBNFΛ/POOVMMͱͯ͠ѻ͍͍͕ͨɺ7JFXͷॳ ظԽίϯετϥΫλͰͳ͘PO$SFBUF ͳͲ "OESPJEͷϥΠϑαΠΫϧʹͳΔͷͰΤϥʔʹͳͬͯ ͠·͏
lateinit class View : RelativeLayout { private lateinit var name:
String fun initView(name: String) { this.name = name } } MBUFJOJUΛ͚Δ͜ͱͰɺॳظԽ͕ίϯετϥΫλ֎ ͰߦΘΕΔ͜ͱΛ໌ࣔͰ͖Δɻ ͨͩ͠ɺॳظԽ͠Εͨ߹ 6OJOJUJBMJ[FE1SPQFSUZ"DDFTT&YDFQUJPO͕ൃੜ
·ͱΊ - KotlinJavaʹม͞Εͯಈ͘ɻͭ·ΓJavaɻ - Kotlinͷຊ࣭NullSafetyͳͲʹ͋Γɺίʔυ ͷॻ͖ํඍʑͨΔͷͰ͢ɻ׳Εͳ͍ง ғؾͰॻ͍ͯOK - lazyɺapplyɺlateinitΛ͍͜ͳ͢͜ͱͰΑΓ KotlinΒ͘͠ͳΔ
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠