https://kotlinlang.org logo
Title
f

frellan

06/10/2018, 10:06 PM
I may have found something the smart cast compiler don’t find (or is it just the intellij plugin?)
for (i in 0 until listA.size) {
	if (listB[i] == null || listC[i] == null) continue

	val b = listB[i]
	val c = listC[i]
}
In the above example, neither
b
nor
c
is smart casted to a non null variable. I am forced to do this:
for (i in 0 until listA.size) {
	if (listB[i] == null || listC[i] == null) continue

	val b = listB[i]!!
	val c = listC[i]!!
}
Am I doing something wrong? Anybody encountered issues with smart cast and
continue
?
g

gildor

06/11/2018, 3:24 AM
It’s impossible to smart cast those map calls, map content can be changed, so it’s not safe consider that value is still there
Just assign
listB[i]
to local variables and check them for null and in this case smart cast will work for your