I have tried the solution above with tryCast<Array<String?>>
and, I guess, in my specific task in listing with many castings involved it was no so great idea, because it was slowing the performance drastically.
This is the solution I did finally - manually check the entries and call methods, like this:
fun foo() {
val map: Map<String?, Any?> = mapOf()
map.forEach { entry ->
when (entry.value) {
is String -> {
doSomeWork(entry.key, entry.value as String)
}
is Array<*> -> {
doSomeWork(entry.key, (entry.value as? Array<*>)?.map {
if (it is String) {
it
} else null
}?.toList())
}
}
}
}
private fun doSomeWork(key: String?, value: String) {
}
private fun doSomeWork(key: String?, values: List<String?>?) {
}