I am genuinely shocked on how hard it is to find a good explanation on how to create a 2d array in Kotlin for an object.
These are my attempts from what I have found neither here on stack and online neither work, why? how do I create a 2d array of objects not built into Kotlin!!!
var matrix : Array<Array<myObject?>> = null
//var arr2D = Array(10) { Array(10) { myObject(this) } }
for (i in 0 until 9) {
for (j in 0 until 9) {
matrix[i][j] = myObject(this)
}
}
It says "null can not be a value of a non-null type" so I guess I have to use an arrayofnulls(), but cannot find a source can someone help me or give me a source?