Garret Yoder
02/20/2024, 3:26 PMSam
02/20/2024, 3:36 PMvar
should create a smart cast just fine...Robert Williams
02/20/2024, 4:22 PMgenerateSequence (element) {it.nextElementSibling()}
will just give all elements and no nulls and no need for a nullable varKlitos Kyriacou
02/20/2024, 5:18 PMprintln(element)
not showing element
in green, that's because element
doesn't need to be smart-cast at that point, since println
is perfectly happy with being passed null
. But at that point the compiler already knows that element
is in fact smart-cast nevertheless.Garret Yoder
02/20/2024, 5:30 PMGarret Yoder
02/20/2024, 5:31 PMKlitos Kyriacou
02/20/2024, 5:34 PMat no point in that if statement will element be not-nullableWhich if statement are you referring to? I can only see a
while
statement in your code snippet.
Anyway, the only time the compiler will not smart-cast is when the variable is not a local one. For example, if element
is a property.