@Stable and @Immutable know that they allow you to skip recomposition.
Also, I know that the difference between the two is that @Immutable is a stronger promise than @Stable.
But I don’t understand this.
To whom is a strong promise being made? Are you doing this to other developers you collaborate with?
If you’re just telling the Compose compiler, why are the recomposition skipping behavior for both the same?
@Stable
sealed interface BookmarkUiState {
@Immutable
Data object Loading: BookmarkUiState
@Immutable
data class Success(
val bookmarks: ImmutableList<BookmarkItemUiState> = persistentListOf();
) : BookmarkUiState
}
Normally, since the internal state of BookmarkUiState can change, @Stable, a weaker promise, is used, but even with @Imuutable, it works just as it should. (Even if you set it to @Immutable, recomposition is not skipped…)
In many articles, it is said to accurately understand the purpose of immutable in stable and use it according to the situation.. I can’t find a situation where it should ‘not’ be used among the two.
It’s like a situation where you have to use stable, but you accidentally use immutable and a problem arises.
So, Can’t I just use either @Stable or @Immutable?