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
120
Kotlin Inline Class
Takuji Nishibayashi
April 12, 2019
Tweet
Share
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
CameraX使ってみた
takuji31
0
40
kotlinx.datetime 使ってみた
takuji31
0
150
HiltのCustom Componentについて
takuji31
0
110
java.timeをAndroidで使う
takuji31
0
47
KSPを使ってコード生成
takuji31
0
250
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
890
kotlinx.serialization
takuji31
0
510
kanmoba-returns-02.pdf
takuji31
0
160
AndroidXとKotlin Coroutines
takuji31
0
310
Other Decks in Technology
See All in Technology
Developer Experienceを向上させる基盤づくりの取り組み事例集
coconala_engineer
0
130
Oracle Exadata Database Service(Dedicated Infrastructure):サービス概要のご紹介
oracle4engineer
PRO
0
9.5k
DroidKaigi 2024 たすけて!ViewModel
mhidaka
5
650
Privacy Sandbox on Android / DroidKaigi 2024
7pairs
1
210
サプライチェーン攻撃に備える
ryunen344
0
190
株式会社M2X エンジニアチーム紹介資料
m2xsoftware
0
660
グイグイ系QAマネージャーの仕事
sadonosake
0
240
サーバー管理しないサーバーサービスManaged DevOps Pool
kkamegawa
0
120
20240912 JJUGナイトセミナー
mii1004
0
140
エンジニア視点で見る、 組織で運用されるデザインシステムにするには
shunya078
1
300
Google CloudのLLM活用の選択肢を広げるVertex AIのパートナーモデル
nayuts
0
120
やってやろうじゃないかメカアジャイル! / Let's do it, mechanical agile!
psj59129
1
390
Featured
See All Featured
Optimizing for Happiness
mojombo
375
69k
How to name files
jennybc
75
98k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
103
48k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
27
7.4k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
248
20k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
43
2k
VelocityConf: Rendering Performance Case Studies
addyosmani
322
23k
Producing Creativity
orderedlist
PRO
340
39k
Debugging Ruby Performance
tmm1
72
12k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
502
140k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
25
3.9k
The World Runs on Bad Software
bkeepers
PRO
64
11k
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/