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
85
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
2025.01.17_Sansan × DMM.swift
riofujimon
2
670
Package Traits
ikesyo
2
230
functionalなアプローチで動的要素を排除する
ryopeko
1
960
WebDriver BiDiとは何なのか
yotahada3
1
100
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
1
790
traP の部内 ISUCON とそれを支えるポータル / PISCON Portal
ikura_hamu
0
230
Terraform で作る Amazon ECS の CI/CD パイプライン
hiyanger
0
110
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
990
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
0
130
動作確認やテストで漏れがちな観点3選
starfish719
5
880
Rubyでつくるパケットキャプチャツール
ydah
0
540
AWS re:Invent 2024個人的まとめ
satoshi256kbyte
0
150
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
89
5.8k
Writing Fast Ruby
sferik
628
61k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
990
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
600
Site-Speed That Sticks
csswizardry
3
310
BBQ
matthewcrist
85
9.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Agile that works and the tools we love
rasmusluckow
328
21k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
51k
Documentation Writing (for coders)
carmenintech
67
4.6k
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