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
65
J2Kコンバータをカスタマイズする ver: 5min
paraya3636
0
1.7k
J2Kコンバータをカスタマイズする
paraya3636
1
2.1k
命名おじさん
paraya3636
1
120
DDD失敗談
paraya3636
0
96
Other Decks in Programming
See All in Programming
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
350
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
110
イマのCSSでできる インタラクション最前線 + CSS最新情報
clockmaker
5
3.1k
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
130
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.9k
Tauriでネイティブアプリを作りたい
tsucchinoko
0
380
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
CSC509 Lecture 12
javiergs
PRO
0
160
Remix on Hono on Cloudflare Workers
yusukebe
1
320
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
40
2.4k
YesSQL, Process and Tooling at Scale
rocio
169
14k
BBQ
matthewcrist
85
9.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Building Your Own Lightsaber
phodgson
103
6.1k
Embracing the Ebb and Flow
colly
84
4.5k
Building an army of robots
kneath
302
43k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
140
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Β͘͠ͳΔ
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠