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
Kotlin Inline Class
Search
Takuji Nishibayashi
April 12, 2019
Technology
0
140
Kotlin Inline Class
Takuji Nishibayashi
April 12, 2019
Tweet
Share
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
CameraX使ってみた
takuji31
0
86
kotlinx.datetime 使ってみた
takuji31
0
330
HiltのCustom Componentについて
takuji31
0
190
java.timeをAndroidで使う
takuji31
0
73
KSPを使ってコード生成
takuji31
0
310
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
990
kotlinx.serialization
takuji31
0
550
kanmoba-returns-02.pdf
takuji31
0
180
AndroidXとKotlin Coroutines
takuji31
0
340
Other Decks in Technology
See All in Technology
Postman と API セキュリティ / Postman and API Security
yokawasa
0
200
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
2
2.2k
Snykで始めるセキュリティ担当者とSREと開発者が楽になる脆弱性対応 / Getting started with Snyk Vulnerability Response
yamaguchitk333
2
180
アップデート紹介:AWS Data Transfer Terminal
stknohg
PRO
0
180
kargoの魅力について伝える
magisystem0408
0
200
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
300
Wantedly での Datadog 活用事例
bgpat
1
430
Snowflake女子会#3 Snowpipeの良さを5分で語るよ
lana2548
0
220
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
530
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
100
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
250
Amazon SageMaker Unified Studio(Preview)、Lakehouse と Amazon S3 Tables
ishikawa_satoru
0
150
Featured
See All Featured
Speed Design
sergeychernyshev
25
670
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
A designer walks into a library…
pauljervisheath
204
24k
We Have a Design System, Now What?
morganepeng
51
7.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Navigating Team Friction
lara
183
15k
How STYLIGHT went responsive
nonsquared
95
5.2k
A Tale of Four Properties
chriscoyier
157
23k
Transcript
KotlinͷInline classΛAndroidΞϓϦ Ͱ׆༻͢Δ @takuji31 Mobile Act OSAKA #9
ࣗݾհ
ࣗݾհ • @takuji31 id:takuji31 • Takuji Nishibayashi • Hatena Co.,
Ltd. • App Team • ίϛοΫDAYS • δϟϯϓϧʔΩʔʂ • ΧΫϤϜ
ࣗݾհ • Android • Kotlin • Flu-er • ! h-ps:/
/blog.takuji31.jp • " h-ps:/ /nazuna.takuji31.jp • # $ h-ps:/ /photo.takuji31.jp
ಥવͰ͕࣭͢Ͱ͢
AndroidΞϓϦ ։ൃͯ͠·͔͢ʁ
Kotlin ͬͯ·͢ΑͶʁ
͍·͢ΑͶʁ
ಛผͳҙຯΛ࣋ͭ ϓϦϛςΟϒܕͷ ͋Γ·͢ΑͶʁ
ྫ͑
ID
࣌
URLͷςϯϓϨʔτ
APIͰड͚औͬͨΓ
ը໘ͷύϥϝʔλʔʹͨ͠Γ
ྫ͑ID͕શ෦Stringͩͱ Α͔͘Βͳ͍
͏͔ͬΓϢʔβʔͷID͖͢ͱ͜ Ζʹ ผͷIDΛͯ͠͠·͏
ܕͰͳΜͱ͔͍ͨ͠
Inline class
Inline class • ࡞Γํ • APIͷϨεϙϯεͰ • ը໘ͷύϥϝʔλʔͱͯ͠
࡞Γํ
Inline class UserId( val value: String // single value only
)
؆୯Ͱ͢Ͷ
APIͷϨεϙϯεͰ
{ "id": "1234567890", "name": "takuji31", "iconUrlTemplate": "https://takuji31.jp/icon.png?size={size}", "lastLoggedInAt": "2019-04-09T01:23:45+09:00", "birthday":
"1987-03-01" }
No Inline classes data class User( val id: String, val
name: String, val iconUrlTemplate: String, val lastLoggedInAt: String, val birthday: String )
With Inline classes data class User( val id: UserId, val
name: String, val iconUrlTemplate: UrlTemplate, val lastLoggedInAt: DateTimeString, val birthday: DateString )
Parse͢Δ
kotlinx.serializa.on
Not supported
Gson
JavaͷReflec(onͰ ݩͷܕͱͯ͠ೝࣝ͞ΕΔ →Կ͠ͳͯ͘Α͍
Moshi
Reflec%on
Not supported
Codegen
objectͱͯ͠ೝࣝ͠Α͏ͱ͢Δ→ࢮ
AdapterΛ࡞Δ
ࣗಈੜͰ͖Δͱ͍͍͔ʁ
APIͷϨεϙϯεͰ • ఆٛ؆୯ • ͏ͷ؆୯ • γϦΞϥΠζ͢Δ࣌πʔϧΛબͼͦ͏ • Gson •
Moshi Codegen + Կ͔ͰAdapterੜ
ը໘ͷύϥϝʔλʔͱͯ͠
Jetpack Naviga-on Safe Args
<fragment android:id="@+id/user" android:name="jp.takuji31.inline.UserFragment" > <argument android:name="id" app:argType="jp.takuji31.inline.UserId" /> </fragment>
ͦͷ··ͩͱSafe ArgsʹInline class ͕ͤͳ͍
Serializableʹ͢Δ
inline class UserId(val value: String) : Serializable
fun openUserScreen(user: User) { findNavController() .navigate( R.id.action_home_to_user, UserFragmentArgs(user.id).toBundle() ) }
private val args: UserFragmentArgs by navArgs() override fun oncreate(savedInstanceState: Bundle?)
{ super.onCreate(savedInstanceState) val userId = args.id // do something }
h"ps:/ /github.com/takuji31/inline- class-example
ExperimentalͳͷͰ ͝ར༻ܭըతʹ
data classͰ༻͢Δͷ ͝ݕ౼͍ͩ͘͞
enjoy Inline class life
! ࠾༻ใ
גࣜձࣾͯͳͰɺ ͱʹʮઓʯͰ͖Δ ؒΛืू͍ͯ͠·͢
͜ΜͳਓΛ୳͍ͯ͠·͢ • AndroidΞϓϦΛ࡞Γ͍ͨਓ • iOSΞϓϦΛ࡞Γ͍ͨਓ • ͋Δ͍྆ํ • ͳΜͳΒαʔόʔαΠυ
h"ps:/ /hatenacorp.jp/recruit/