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
Using Kotlin in Android
Search
Ivan
May 03, 2019
Programming
0
110
Using Kotlin in Android
Kotlin examples for study group in Taiwan Kotlin User Group
Ivan
May 03, 2019
Tweet
Share
More Decks by Ivan
See All by Ivan
KtRssReader 的奇幻旅程
ivanw
0
91
Kotlin Flow Application and Testing on Android
ivanw
0
310
Kotlin Flow Application and Testing on Android
ivanw
1
450
A Step-by-Step Guide to Kotlin Flow 手把手帶你認識 Kotlin Flow
ivanw
0
210
Coroutines Made Easy
ivanw
1
190
All About KotlinConf 2019
ivanw
0
130
Writing Tests in Kotlin
ivanw
0
340
Other Decks in Programming
See All in Programming
Inside of Swift Export
giginet
PRO
1
340
ネストしたdata classの面倒な更新にさようなら!Lensを作って理解するArrowのOpticsの世界
shiita0903
1
260
SwiftDataを使って10万件のデータを読み書きする
akidon0000
0
250
AIのバカさ加減に怒る前にやっておくこと
blueeventhorizon
0
150
AIと人間の共創開発!OSSで試行錯誤した開発スタイル
mae616
2
880
ALL CODE BASE ARE BELONG TO STUDY
uzulla
30
6.9k
KoogではじめるAIエージェント開発
hiroaki404
1
300
CSC305 Lecture 13
javiergs
PRO
0
350
業務でAIを使いたい話
hnw
0
230
品質ワークショップをやってみた
nealle
0
940
iOSでSVG画像を扱う
kishikawakatsumi
0
180
AsyncSequenceとAsyncStreamのプロポーザルを全部読む!!
s_shimotori
1
230
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
412
23k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
Embracing the Ebb and Flow
colly
88
4.9k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
850
Balancing Empowerment & Direction
lara
5
710
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
192
56k
Building an army of robots
kneath
306
46k
Typedesign – Prime Four
hannesfritz
42
2.9k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
Designing Experiences People Love
moore
142
24k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Gamification - CAS2011
davidbonilla
81
5.5k
Transcript
Using Kotlin in Android Ivan W.
Outline • Null Safety • Data Class • Default Argument
/ Implementation 2
Null Safety • Eliminate the danger of null references from
code • Nullable types and Non-Null Types var a: String = "abc" a = null // compilation error var b: String? = "abc" b = null // ok 3 Nullable types Non-Null types
Example 1 4 Bundle args = getArguments(); if (args !=
null) { Bundle data = args.getBundle(KEY_DATA); if (data != null) { Log.d(TAG, data.getString(KEY_NAME)); } } Java
Example 1 5 Bundle args = getArguments(); if (args !=
null) { Bundle data = args.getBundle(KEY_DATA); if (data != null) { Log.d(TAG, data.getString(KEY_NAME)); } } Log.d(TAG, arguments?.getBundle(KEY_DATA)?.getString(KEY_NAME)) Java Kotlin
Data Class • It automatically generates ◦ equals() / hashCode()
◦ getters and setters ◦ toString() ◦ copy()
Example 2 7 Java Kotlin See example See example
Default Argument / Implementation 8 • Java overloads can be
replaced with one function in Kotlin
Example 3 9 private void sendInfo(String content, long Time, String
tag) { /* ... */ } private void sendInfo(String content, long Time) { /* ... */ } private void sendInfo(String content, String tag) { /* ... */ } private void sendInfo(String content) { /* ... */ } Java
Example 3 10 private fun sendInfo( content: String, time: Long
= Date().time, tag: String = TAG ) { … } sendInfo("content", time = Date().time) Kotlin
Example 4 11 Java Kotlin See example See example
Thank you! 12