https://kotlinlang.org logo
#android
Title
# android
a

Abhimanyu

11/05/2023, 2:12 AM
Hi everyone, What is the type safe way to extract list of specific data type in given position from
Array<Any?>
?
Copy code
fun main() {
    val x: Array<Any?> = arrayOf(listOf(1, 2, 3), listOf('a', 'b', 'c'))
    val y = x[0] as? List<Int> ?: emptyList()
    val z = x[1] as? List<Char> ?: emptyList()
    y.forEach {
        println(it)
    }
    z.forEach {
        println(it)
    }
}
y
has
Unchecked cast: Any? to List<Int>
and
z
has
Unchecked cast: Any? to List<Char>
. How to fix this properly?
plus1 1