Is the Type still consider Immutable/Stable for Co...
# compose
s
Is the Type still consider Immutable/Stable for Compose? if the class is something like this 🧵
@Immutable data class SomeClass( val someString: Char? = null val map: Map<String,Any?>?= null )
n
I would say no? “Any?” could be assigned a value which is mutable? Open to others suggestions.
Copy code
val immutableMap:Map<String,Any?>? = mapOf(Pair("test", mutableListOf(1)))
 (immutableMap!!["test"] as MutableList<Int>).add(2)
Above is my thinking why its not immutable. Compose would not be notified when you added the item to the mutable list.
m
But isn't that annotation used to force Compose to think it is immutable - promise you don't mutate it even while you can?
n
Yeap it is to tell compose its immutable. I guess it depends on what the question is. We can add this annotation but we run the risk that someone else then uses the type in a way which isn’t truly immutable with odd results.
My go to thread for conceptualising some of this https://kotlinlang.slack.com/archives/CJLTWPH7S/p1622465932419200
đź‘Ť 1