Se7eN
09/04/2021, 1:53 PMclass Element {
var position: Offset by mutableStateOf(...)
var rotation: Float by mutableStateOf(...)
...
}
// Then I can do this:
val element = Element(...)
element.position = newPosition
I want to pass this element
object to a composable but don't want it to be mutable. I can create a similar class for an immutable element but then I'd have to update the immutable class whenever I change the Element
class. Is there something else I can do?Zach Klippenstein (he/him) [MOD]
09/04/2021, 1:58 PMSe7eN
09/05/2021, 8:36 AMElement
.
Don't really understand what's the difference between immutability and read-only here 🤔
But I'll try the interface thing and see if that's what I wantSe7eN
09/05/2021, 6:49 PMZach Klippenstein (he/him) [MOD]
09/06/2021, 12:23 AMList
vs MutableList
– a MutableList
is a List
, but not the other way around, so if you only have a List
you can’t change it but the list can still be changed out from under you if it’s a MutableList
under the hood and someone else is mutating it).
Immutable is a stronger guarantee, meaning a thing can’t change at all.