'What does mean @Stable and @Immutable annotation in Jetpack Compose?
While studying through the Jetpack Compose sample project, I saw @Stable and @Immutabe annotations. I've been looking through the Android documentation and GitHub about those annotations, but I don't understand.
From what I understand, if use @Immutable, even if the state is changed, recomposition should not occur. However, as a result of the test, recomposition proceeds.
What exactly do @Stable and @Immutable annotations do in Jetpack Compose?
Solution 1:[1]
The compiler treats both identically but
- using
@Immutableis a promise that the value will never change. - using
@Stableis a promise that the value is observable and if it does change listeners are notified.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gabriele Mariotti |
