Jon Bailey
05/26/2024, 11:23 AMfun <T> mutableStateOf(value: T)
fun mutableStateOf(value: Int)
shikasd
05/26/2024, 11:33 AMJon Bailey
05/26/2024, 11:42 AMmutableStateOf<Int>(0)
? Also do you mean return this value from a lambda like using it inside remember?Jon Bailey
05/26/2024, 11:42 AMshikasd
05/26/2024, 11:51 AMJon Bailey
05/26/2024, 12:10 PMAndrew Bailey
05/26/2024, 4:11 PMMutableIntState
extend MutableState<T>
, which means you can call .value
on it and still get correct behavior. But if you do and you're using the primitive version, it'll box for you on the spot which can actually cause more autoboxing than using the generic API. Theoretically the compiler plugin could've fixed that, but we decided against it since it's too magical of a behavior.
Another detail is for libraries. Changing a public return type from MutableState<T>
to MutableIntState
is no problem but you can't do the opposite without breaking API compatibility. It makes more sense for this to be explicit in case a library is using inferred types in public API. The syntax to opt-out of this would have been clunky, and if you forgot and then later decided you needed an equality policy, your options would have been limited.