Android & Jetpack Compose (50 Qs)•Part 2: Compose Internals, Persistence, DI & Background Work (11 - 24)
What makes a Composable function "Skippable" and what are `@Stable` and `@Immutable`?
senior LevelDocker & Containers
In Simple Words: Compose skips recomposition only if all parameter types are Stable:
- Primitive types (
Int,String), functional lambdas, and classes marked with@Immutableare considered stable. - The Stability Trap: Standard Kotlin
List<T>is an interface; Compose treats it as unstable because a subclass could be mutable (ArrayList), causing the composable to recompose on every parent update! - Fix: Use Kotlinx Immutable Collections (
ImmutableList<T>), or annotate the data class with@Immutable.