These all compile fine:
fun f1(): Array<Any> {
return arrayOf(1)
}
fun f2(): Collection<Any> {
return listOf(1)
}
fun f3(): Collection<Collection<Any>> {
return listOf(listOf(1))
}
But this one gives the error below:
fun f4(): Array<Array<Any>> {
return arrayOf(arrayOf(1)) // compilation error here
}
Error:(22, 16) Kotlin: Type inference failed. Expected type mismatch: inferred type is Array<Array<Int>> but Array<Array<Any>> was expected
Why?