# Immutable

Artifact: [androidx.compose.runtime:runtime-annotation](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/Immutable.kt+class:androidx.compose.runtime.Immutable) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.9.0) Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  @MustBeDocumented
  @Target(allowedTargets = [AnnotationTarget.CLASS])
  @Retention(value = AnnotationRetention.BINARY)
  @StableMarker
  annotation Immutable
  ```

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/Immutable` can be used to mark class as producing immutable instances. The immutability of the class is not validated and is a promise by the type that all publicly accessible properties and fields will not change after the instance is constructed. This is a stronger promise than `val` as it promises that the value will never change not only that values cannot be changed through a setter.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/Immutable` is used by composition which enables composition optimizations that can be performed based on the assumption that values read from the type will not change. See `https://developer.android.com/reference/kotlin/androidx/compose/runtime/StableMarker` for additional details.

`data` classes that only contain `val` properties that do not have custom getters can safely be marked as `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Immutable` if the types of properties are either primitive types or also `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Immutable`:

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable

@Immutable data class Person(val name: String, val phoneNumber: String)

@Composable
fun PersonView(person: Person) {
    Column {
        Row {
            Text("Name: ")
            Text(person.name)
        }
        Row {
            Text("Phone: ")
            Text(person.phoneNumber)
        }
    }
}

@Composable
fun PeopleView(people: List<Person>) {
    Column {
        for (person in people) {
            PersonView(person)
        }
    }
}
```

Marking `Person` immutable allows calls the `PersonView` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable` function to be skipped if it is the same `person` as it was during the last composition.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/StableMarker` |   |

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Immutable#Immutable()()` | Cmn |

## Public constructors

### Immutable

Cmn

```
Immutable()
```