Shakil Karim
07/20/2021, 5:42 PM@Immutable
and what will be the difference with @Stable
Code in 🧵Shakil Karim
07/20/2021, 5:43 PMsealed class BADGE(open val text: String)
data class GET(override val text: String) : BADGE(text)
data class OPEN(override val text: String) : BADGE(text)
data class COIN(override val text: String) : BADGE(text)
data class Pack(
val pck: Long,
val owner: Long,
val title: String,
val packNameMap: Map<String,String>,
val type: String,
val coins: Int,
val emoji: String,
val lang: String,
val lections: List<Lection> = emptyList(),
val badge: MutableState<BADGE?> = mutableStateOf(null)
)
Chuck Jazdzewski [G]
07/20/2021, 5:56 PM@Stable
is preferred in this case as the type contains a mutable value, badge
, so is not immutable.
The compiler treats both identically but using @Immutable
is a promise that the value will never change. @Stable
is a promise that the value is observable and if it does change listeners are notified. The latter is more appropriate here.Shakil Karim
07/20/2021, 5:58 PMMBegemot
07/20/2021, 7:44 PM