Travis Griggs
04/18/2024, 8:24 PMvar insideBox: SpanBoxInfo? = null
...
for (spanBoxInfo in spanBoxes(valveSpanList, yAxis, size)) {
val (_, _, spanRect ) = spanBoxInfo
if (spanRect.contains(offset)) {
insideBox = spanBoxInfo
} else if ...
}
return if (insideBox != null) {
"inside" to insideBox
} else if ...
I have a preference for .forEach
and wanted to apply that here. But when I do, the smart null pointer casting doesn't work at the bottom anymore. Why is that?Youssef Shoaib [MOD]
04/18/2024, 11:33 PMlateinit var
I thinkJuan Carlos
04/19/2024, 7:07 AMfirst
or last
.
So maybe something like:
val insideBox = spanBoxes(valveSpanList, yAxis, size)
.last { it.spanRect.contains(offset) }
// then, as its a val, the smart null pointer casting should work as usual
Klitos Kyriacou
04/19/2024, 10:02 AMfun foo() {
var v: Int? = null
// You just need to reference v inside a lambda for the compiler to not
// know whether v can subsequently change value between check & use
{
v = 5
}
if (v != null) {
println(v + 1) // ERROR: v may be null
}
}
Update: the above compiles ok with 2.0.0-RC1.