I’m trying to remember a custom object I don’t want to mutate during the composable lifecycle but I don’t want it to be recreated neither. It works well with
Copy code
val myCustomObject by remember { mutableStateOf(MyCustomObject()) }
If I try without
mutableStateOf
I get the following compiler error
Property delegate must have a 'getValue(Nothing?, KProperty0<*>)' method
.
I tried to add this to
MyCustomObject
but it didn’t work
Copy code
operator fun getValue(thisRef: Nothing?, property: KProperty0<*>): MyCustomObject = this
I get
'operator' modifier is not applicable to function: second parameter must be of type KProperty<*> or its supertype.
Is there a way to make this work? Or should I do it another way?
c
Chrimaeon
12/25/2024, 10:51 PM
Get yourself familiar with property delegation, what the
by
keyword means and why you cannot use it without the