Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Kotlin2.3明示的バッキングフィールド
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
tonionagauzzi
April 21, 2026
430
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlin2.3明示的バッキングフィールド
tonionagauzzi
April 21, 2026
More Decks by tonionagauzzi
See All by tonionagauzzi
Androidエンジニアが大規模プロダクトのWebフロントエンドとバックエンドに越境して感じたギャップと習得したマインド
tonionagauzzi
0
500
【Android】テキスト選択色の問題修正で心がけたこと
tonionagauzzi
0
300
Android 15以上でPDFのテキスト検索を爆速開発!
tonionagauzzi
0
430
Googleの新しいコーディングAIエージェントJulesを使ってみた
tonionagauzzi
0
900
Compose におけるパスワード自動入力とパスワード保存
tonionagauzzi
0
580
Androidテスト基礎講義
tonionagauzzi
0
440
Android Composeでの自動入力(作成:GPT-4o)
tonionagauzzi
0
180
Jetpack Composeで自動入力(Autofill)を実装しよう(作成:claude-3.7-sonnet)
tonionagauzzi
0
190
Jetpack Composeにおける自動入力の実装と注意点(作成者:Gemini 2.5 Pro Exp 03-25)
tonionagauzzi
0
200
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
Product Roadmaps are Hard
iamctodd
55
13k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Side Projects
sachag
456
43k
WENDY [Excerpt]
tessaabrams
14
40k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Code Review Best Practice
trishagee
74
20k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
740
A designer walks into a library…
pauljervisheath
211
25k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
750
The Invisible Side of Design
smashingmag
301
52k
Transcript
詳解 Kotlin 2.3 明示的バッキングフィールド Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 1
登壇者情報 名前:トニオ(@tonionagauzzi) 所属:サイボウズ株式会社 役割:Androidエンジニア 趣味:ブログ 今日の資料のブログ版:https://dribit.hatenablog.com/entry/2026/04/17/150000 Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会
vol.64 2
突然ですが、こんなコードに見覚えないですか? Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 3
private val _city = MutableStateFlow("") val city: StateFlow<String> get() =
_city Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 4
private val _prefecture = MutableStateFlow("") val prefecture: StateFlow<String> get() =
_prefecture private val _city = MutableStateFlow("") val city: StateFlow<String> get() = _city private val _address = MutableStateFlow("") val address: StateFlow<String> get() = _address private val _building = MutableStateFlow("") val building: StateFlow<String> get() = _building Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 5
アンダースコア・パターンの課題 Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 6
内部 MutableStateFlow / 外部 StateFlow を表現している private val _city =
MutableStateFlow("") val city: StateFlow<String> get() = _city _city という名前が違和感を与える 同じものを扱うプロパティが2つある クラスが大きくなるほど _xxx / xxx のセットが増える Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 7
Kotlin 2.3の明示的バッキングフィールドで解決! Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 8
明示的バッキングフィールドとは? Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 9
プロパティの 公開型 と、値を保持する バッキングフィールドの型 を 別々に宣言できる機能(Kotlin 2.3でExperimental導入) val city: StateFlow<String>
field = MutableStateFlow("") // ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ // 外に見える型 内部で持つ型 公開型は 読み取り専用の型(例: StateFlow , List ) フィールドの型は 変更可能な型(例: MutableStateFlow , MutableList ) _xxx プロパティが不要になる Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 10
明示的じゃないバッキングフィールドってあるの? Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 11
前からあります! Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 12
var name: String = "" set(value) { field = value.trim()
// field がバッキングフィールド } → バッキングフィールドの型を指定できない 制約 プロパティと同じ型しか持てない Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 13
明示的バッキングフィールドのメリット Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 14
① 1つのプロパティで表現 val city: StateFlow<String> field = MutableStateFlow("") 外から見ると StateFlow<String>
クラス内部では MutableStateFlow<String> として見えている 公開型と内部型が異なっても、プロパティは1つでOK Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 15
② スマートキャストが機能 val city: StateFlow<String> field = MutableStateFlow("") fun updateCity(newCity:
String) { city.value = newCity } バッキングフィールドの型を 明示的に指定 できる クラス内部で city.value = newCity で代入できる コンパイラが city のバッキングフィールドをMutableStateFlow と知っているため スマートキャストが機能する Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 16
StateFlow専用なの? Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 17
もちろん、そんなことはありません! Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 18
他の型の組み合わせでも使える MutableList と List の場合 val items: List<String> field =
mutableListOf() fun addItem(item: String) { items.add(item) // 内部では MutableList として操作可能 } 注意:Channel<T> → Flow<T> のような変換ケースは対象外 Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 19
この仕組み、いつから考えられていたの? Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 20
なんと10年前から! Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 21
導入の背景 2016年: YouTrackに要望が登録される KT-14663 2021年: 明示的バッキングフィールドの提案が始まる #278 2025年: 正式仕様が提案される KEEP-0430
2026年: Kotlin 2.3 でExperimental導入! Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 22
現在の制限事項 Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 23
1. コンパイラオプションの有効化が必要 kotlin { compilerOptions { freeCompilerArgs.add("-Xexplicit-backing-fields") } } 2.
バッキングフィールドは常に private protected など他の可視性は設定不可 Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 24
3. コンストラクタプロパティには非対応 プライマリコンストラクタで宣言されたプロパティには適用できない 4. プロパティは val のみ var は不可 Kotlin
2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 25
まとめ 明示的バッキングフィールドはアンダースコア・パターンを改善する新機能 Android開発で MutableStateFlow や MutableList などを扱う場面で効果大 可読性の向上 スマートキャストの恩恵 2016年の要望から10年経ってKotlin
2.3で実現 Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 26
ご清聴ありがとうございました! Dribit Media https://dribit.hatenablog.com/ Kotlin 2.3 明示的バッキングフィールド Kotlin愛好会 vol.64 27