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
64
kotlinx.datetime 使ってみた
takuji31
0
260
HiltのCustom Componentについて
takuji31
0
150
java.timeをAndroidで使う
takuji31
0
59
KSPを使ってコード生成
takuji31
0
290
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
960
kotlinx.serialization
takuji31
0
540
kanmoba-returns-02.pdf
takuji31
0
180
AndroidXとKotlin Coroutines
takuji31
0
330
Other Decks in Technology
See All in Technology
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
500
隣接領域をBeyondするFinatextのエンジニア組織設計 / beyond-engineering-areas
stajima
1
270
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
フルカイテン株式会社 採用資料
fullkaiten
0
40k
安心してください、日本語使えますよ―Ubuntu日本語Remix提供休止に寄せて― 2024-11-17
nobutomurata
1
990
Platform Engineering for Software Developers and Architects
syntasso
1
520
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
470
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
210
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
120
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
300
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
520
39k
Automating Front-end Workflow
addyosmani
1366
200k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
A designer walks into a library…
pauljervisheath
203
24k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Gamification - CAS2011
davidbonilla
80
5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
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/