スキップ、@Stable、@Immutable
型に印を付け、Composeが処理をスキップできるようにします。
「スキップ、@Stable、@Immutable」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはJetpack Compose Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Jetpack Compose Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
When You Need Annotations
Sometimes a type is truly safe but Compose cannot prove it. Annotations let you promise stability so skipping kicks back in.
The @Immutable Promise
@Immutable tells Compose that once an instance is built, none of its properties will ever change. It is the strongest stability guarantee.
@Immutable
data class Theme(val primary: Long, val radius: Int)When to Use @Immutable
Reach for @Immutable on config-like data: themes, styles, and value objects you create once and never mutate after construction.
The @Stable Promise
@Stable is gentler: properties may change, but when they do, Compose will be notified through Compose state. equals() must stay consistent.
@Stable for Observable Types
Use @Stable on classes whose mutable fields are backed by mutableStateOf, so Compose still tracks every change correctly.
@Stable
class FormState { var name by mutableStateOf("") }Break the Promise, Break Compose
These annotations are a contract. If you mark a type stable but mutate it silently, the UI shows stale data and bugs creep in.
Immutable Collection Helpers
Instead of List, pass ImmutableList from kotlinx.collections.immutable. Compose treats it as stable, so list Composables can skip.
fun Tags(items: ImmutableList<String>) { }Functions Stay Stable
Lambda parameters are stable already, but remember a lambda capturing changing values is a new instance each recomposition.
Mark the Whole Class Once
One annotation on the class covers every use of that type as a parameter. You do not annotate at each call site.
Annotations Are Last Resort
Prefer real immutability with val first. Only annotate when the compiler genuinely cannot infer stability on its own.
Verify, Then Trust
After annotating, check that the Composable actually skips. A wrong promise is worse than no promise at all.
Quick Check
Pick the right annotation.
Recap: Promise Wisely
Use @Immutable for never-changing data and @Stable for state-backed mutables. Honor the contract or the UI lies. ✅
よくある質問
「スキップ、@Stable、@Immutable」レッスンは無料ですか?
はい。「スキップ、@Stable、@Immutable」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。
「スキップ、@Stable、@Immutable」で何を学びますか?
型に印を付け、Composeが処理をスキップできるようにします。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Jetpack Compose Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「スキップ、@Stable、@Immutable」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このJetpack Compose Academyレッスンでコードを書いて実行できますか?
はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 安定したパラメータと不安定なパラメータ
- スキップ、@Stable、@Immutable
- 状態の読み取りを遅延させる
- Layout Inspectorと再コンポジション回数