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

Yann Badoual

09/26/2020, 8:11 PM
Is
State
considered
Stable
because any changes will cause a recomposition? (If not then why?)
y

Yann Badoual

09/26/2020, 8:29 PM
1) The result of [equals] will always return the same result for the same two instances.
Isn't this line ambiguous though? Since
value
is mutable in
MutableState
, if you change the value between two equals, wouldn't the result differ?
Copy code
var value1 by mutableStateOf(0)
var value2 by mutableStateOf(0)

value1 == value2 // true
value1 = 1
value1 == value2 // false
Feels like the description is not clear enough, or maybe I'm missing something.
"for the same two instances"
should be more precise maybe
a

Adam Powell

09/26/2020, 8:48 PM
this is
equals
on the
@Stable
object instances, not on
.value
so as per the example above,
Copy code
var state1 = mutableStateOf(0)
var state2 = mutableStateOf(0)

state1 == state2 // false
state1.value = 1
state1 == state2 // false
the property delegation hides the real objects that must be
.equals
for the stability contract
y

Yann Badoual

09/26/2020, 9:02 PM
Ooooh, I thought
State
.equals
implementation was comparing values. Ok that makes sense now. Thanks!
👍 1
3 Views