https://kotlinlang.org logo
#compose
Title
# compose
s

Shakil Karim

07/27/2021, 11:05 AM
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

Nathan Castlehow

07/27/2021, 12:07 PM
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

mcpiroman

07/27/2021, 12:21 PM
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

Nathan Castlehow

07/27/2021, 12:22 PM
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
3 Views