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
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
230
良いユニットテストを書こう
mototakatsu
10
3.2k
Zoneless Testing
rainerhahnekamp
0
120
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
960
return文におけるstd::moveについて
onihusube
1
1.3k
テストコード書いてみませんか?
onopon
2
220
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1k
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
290
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
660
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
160
php-conference-japan-2024
tasuku43
0
370
命名をリントする
chiroruxx
1
460
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Building Your Own Lightsaber
phodgson
103
6.1k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
What's in a price? How to price your products and services
michaelherold
244
12k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
KATA
mclloyd
29
14k
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