I absolutely love the smart casting of Kotlin, it’s been really helpful, but there are some things I wish it did. Now, I’m not sure if it’s possible, but when filtering a list for only type (say) String, could Kotlin smart cast the returned list to be a list of Strings?
list.filter {it is String}
.forEach {println(it.length)}
To be fair, that specific example could be done by simply be done by ignoring the filter step, but that’s just to give an idea of what I was referencing. This way, if we have a list (say from a library) that could return multiple types of objects, we could filter by the type we wanted to deal with, and then smart casting would prevent us from having to say “is String” every time we wanted to use it in the rest of the loops.