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
74
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
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
270
KubeCon NA 2024 Recap / Running WebAssembly (Wasm) Workloads Side-by-Side with Container Workloads
z63d
1
250
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
Amazon SageMaker Unified Studio(Preview)、Lakehouse と Amazon S3 Tables
ishikawa_satoru
0
160
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
150
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
350
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
170
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
290
GitHub Copilot のテクニック集/GitHub Copilot Techniques
rayuron
37
14k
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
110
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
490
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Building an army of robots
kneath
302
44k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Docker and Python
trallard
42
3.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
How GitHub (no longer) Works
holman
311
140k
Speed Design
sergeychernyshev
25
670
A designer walks into a library…
pauljervisheath
204
24k
Practical Orchestrator
shlominoach
186
10k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
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/