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
100
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
82
Kotlin Flow Application and Testing on Android
ivanw
0
290
Kotlin Flow Application and Testing on Android
ivanw
1
430
A Step-by-Step Guide to Kotlin Flow 手把手帶你認識 Kotlin Flow
ivanw
0
190
Coroutines Made Easy
ivanw
1
180
All About KotlinConf 2019
ivanw
0
130
Writing Tests in Kotlin
ivanw
0
330
Other Decks in Programming
See All in Programming
Beyond ORM
77web
9
1.3k
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
290
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
2
460
Kaigi on Railsに初参加したら、その日にLT登壇が決定した件について
tama50505
0
110
선언형 UI에서의 상태관리
l2hyunwoo
0
200
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
110
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
170
Zoneless Testing
rainerhahnekamp
0
120
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
350
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
190
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
850
Jaspr Dart Web Framework 박제창 @Devfest 2024
itsmedreamwalker
0
100
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Navigating Team Friction
lara
183
15k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
180
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
RailsConf 2023
tenderlove
29
940
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
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