Ignorando, @Stable e @Immutable
Marque tipos para que o Compose possa ignorar trabalho.
Ignorando, @Stable e @Immutable é uma aula grátis de Jetpack Compose Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Jetpack Compose Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Jetpack Compose Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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. ✅
Perguntas Frequentes
A aula “Ignorando, @Stable e @Immutable” é grátis?
Sim — o texto completo de “Ignorando, @Stable e @Immutable” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Jetpack Compose Academy, atualize para CoddyKit PRO. O curso de Jetpack Compose Academy inclui 4 aulas no total.
O que vou aprender em “Ignorando, @Stable e @Immutable”?
Marque tipos para que o Compose possa ignorar trabalho. Você pratica Jetpack Compose Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Jetpack Compose Academy?
Nenhuma experiência prévia é necessária. Jetpack Compose Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “Ignorando, @Stable e @Immutable”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Jetpack Compose Academy?
Sim. Cada aula de Jetpack Compose Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Parâmetros Estáveis e Instáveis
- Ignorando, @Stable e @Immutable
- Adiar Leituras de Estado
- Inspetor de Layout e Contagens de Recomposição