Stylianos Gakis
01/16/2023, 12:49 PM!!
to pass a non-null version of a nullable local mutable state like this:
@Composable fun foo() {
var x : Int? by remember { mutableStateOf(0) }
if (x != null) {
Bar(x!!)
} else {
...
}
}
Or is there a chance that my !!
there will be problematic and actually crash?hfhbd
01/16/2023, 12:55 PMstable
delegates to allow smartcasts: https://youtrack.jetbrains.com/issue/KT-27325/Allow-smartcasts-for-well-behaved-delegatesephemient
01/16/2023, 12:59 PM@MonotonicNonNull
doesn't work for this since x = null
is allowedStylianos Gakis
01/16/2023, 1:02 PMephemient
01/16/2023, 1:03 PMvar x : Int? by remember {
mutableStateOf(0).apply {
thread {
while (true) {
Thread.sleep(100)
setValue(null)
Thread.sleep(100)
setValue(1)
}
}
}
}
has the all the same typeshfhbd
01/16/2023, 1:03 PMephemient
01/16/2023, 1:04 PMlazy
case (which is truly well-behaved)Stylianos Gakis
01/16/2023, 1:05 PM!!
in such places.ephemient
01/16/2023, 1:08 PMval (x, setX) = remember { mutableStateOf<Int?>(0) }
if (x != null) { ... }
setX(...)
Stylianos Gakis
01/16/2023, 1:13 PM