0Pricing
Jetpack Compose Academy · Lección

Omisión, @Stable y @Immutable

Marque los tipos para que Compose pueda omitir trabajo.

Omisión, @Stable y @Immutable es una lección gratuita de Jetpack Compose Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Jetpack Compose Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Jetpack Compose Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en 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. ✅

Preguntas frecuentes

¿La lección «Omisión, @Stable y @Immutable» es gratis?

Sí — el texto completo de «Omisión, @Stable y @Immutable» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Jetpack Compose Academy, actualiza a CoddyKit PRO. El curso de Jetpack Compose Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Omisión, @Stable y @Immutable»?

Marque los tipos para que Compose pueda omitir trabajo. Practicas Jetpack Compose Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Jetpack Compose Academy?

No se requiere experiencia previa. Jetpack Compose Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «Omisión, @Stable y @Immutable»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Jetpack Compose Academy?

Sí. Cada lección de Jetpack Compose Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Parámetros estables frente a inestables
  2. Omisión, @Stable y @Immutable
  3. Diferir las lecturas de estado
  4. Layout Inspector y recuento de recomposiciones
← Volver a Jetpack Compose Academy