我有一个二维节点数组,我希望使用Kotlin数组的flatten函数将其展平为所有节点的单个数组.
val nodes = kotlin.Array(width, { width ->
kotlin.Array(height, { height -> Node(width, height) })
})
Run Code Online (Sandbox Code Playgroud)
然后我尝试在2D数组上调用flatten函数
nodes.flatten()
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误:Type mismatch: inferred type is Array<Array<Node>> but Array<Array<out ???>> was expected.还有另一种方法我应该这样做吗?