Rick Regan
01/11/2022, 12:46 AMlateinit var myState: MutableState<MyState>
then I have to reference with myState.value.myProperty
. If I do var myState: MyState? by mutableStateOf(null)
then I have to reference with myState?.myProperty
(or other ways of dealing with nullable types). Is there a form that lets you use myState.myProperty
with lateinit
?Adam Powell
01/11/2022, 1:09 AMprivate var _myState by mutableStateOf<MyState?>(null)
var myState: MyState
get() = _myState ?: error("myState was not initialized")
set(value) {
_myState = value
}
and hopefully you aren't using lateinit
often enough for the above to be cumbersome at scale 🙃Adam Powell
01/11/2022, 1:11 AMlateinit
, (b) you could write your own implementation of the MutableState<T>
interface and a lateinitMutableStateOf
factory function of your own that does the above for you and reuse the existing property delegate functionsRick Regan
01/11/2022, 1:24 AM