I am using data class as immutable single state be...
# getting-started
a
I am using data class as immutable single state being emitted from view model. I print the entire state object when it is emitting, Is there a way to find which property is last updated ?
Copy code
data class SomeState(
    val property1: String,
    val property2: String
) {
    override fun toString(): String {
        return "property XX updated"
    }
}
j
The class is immutable, so no property is ever updated in this instance. Do you mean that you
copy()
instances of your state by changing only one of the properties, and you want to know in the new state which one was different from the previous state? This would require manual implementation
a
Yes I do copy() by changing one property and want to know which was updated. Can I do something overriding copy() method ?
j
I think you should rather write your own methods to change each property, but overriding copy is probably possible too. I never tried to do it
👍 1