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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
99
Kotlin Flow Application and Testing on Android
ivanw
0
320
Kotlin Flow Application and Testing on Android
ivanw
1
460
A Step-by-Step Guide to Kotlin Flow 手把手帶你認識 Kotlin Flow
ivanw
0
220
Coroutines Made Easy
ivanw
1
190
All About KotlinConf 2019
ivanw
0
130
Writing Tests in Kotlin
ivanw
0
350
Other Decks in Programming
See All in Programming
CS教育のDX AIによる育成の効率化
niftycorp
PRO
0
160
今からFlash開発できるわけないじゃん、ムリムリ! (※ムリじゃなかった!?)
arkw
0
150
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
230
「効かない!」依存性注入(DI)を活用したAPI Platformのエラーハンドリング奮闘記
mkmk884
0
180
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
440
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
160
CSC307 Lecture 15
javiergs
PRO
0
260
存在論的プログラミング: 時間と存在を記述する
koriym
4
460
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
310
実践ハーネスエンジニアリング #MOSHTech
kajitack
6
2.8k
Feature Toggle は捨てやすく使おう
gennei
0
320
Reactive ❤️ Loom: A Forbidden Love Story
franz1981
2
150
Featured
See All Featured
My Coaching Mixtape
mlcsv
0
85
Java REST API Framework Comparison - PWX 2021
mraible
34
9.2k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.7k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
A Tale of Four Properties
chriscoyier
163
24k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1k
What's in a price? How to price your products and services
michaelherold
247
13k
GraphQLとの向き合い方2022年版
quramy
50
14k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
190
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