Hi, I have a data class, is it correct to mark thi...
# compose
s
Hi, I have a data class, is it correct to mark this class as
@Immutable
and what will be the difference with
@Stable
Code in 🧵
K 3
Copy code
sealed 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)
)
c
@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.
s
@Chuck Jazdzewski [G] Thanks 👍
m
What an awful name to name a thing that the value is observable and if it does change listeners are notified ... terrific IMHO