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
66
kotlinx.datetime 使ってみた
takuji31
0
260
HiltのCustom Componentについて
takuji31
0
150
java.timeをAndroidで使う
takuji31
0
60
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
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
310
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
480
強いチームと開発生産性
onk
PRO
35
11k
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
250
Can We Measure Developer Productivity?
ewolff
1
150
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
アジャイルでの品質の進化 Agile in Motion vol.1/20241118 Hiroyuki Sato
shift_evolve
0
170
The Role of Developer Relations in AI Product Success.
giftojabu1
0
130
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
180
Featured
See All Featured
Side Projects
sachag
452
42k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Embracing the Ebb and Flow
colly
84
4.5k
Six Lessons from altMBA
skipperchong
27
3.5k
Building an army of robots
kneath
302
43k
Writing Fast Ruby
sferik
627
61k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Building Your Own Lightsaber
phodgson
103
6.1k
Code Reviewing Like a Champion
maltzj
520
39k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
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/