I\'m not sure what the difference between an IntArray and an Array is in Kotlin and why I can\'t used them interchangeably:
Array is an Integer[] under the hood, while IntArray is an int[]. That's it.
This means that when you put an Int in an Array, it will always be boxed (specifically, with an Integer.valueOf() call). In the case of IntArray, no boxing will occur, because it translates to a Java primitive array.
Other than the possible performance implications of the above, there's also convenience to consider. Primitive arrays can be left uninitialized and they will have default 0 values at all indexes. This is why IntArray and the rest of the primitive arrays have constructors that only take a size parameter:
val arr = IntArray(10)
println(arr.joinToString()) // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
In contrast, Array doesn't have a constructor that only takes a size parameter: it needs valid, non-null T instances at all indexes to be in a valid state after creation. For Number types, this could be a default 0, but there's no way to create default instances of an arbitrary type T.
So when creating an Array, you can either use the constructor that takes an initializer function as well:
val arr = Array(10) { index -> 0 } // full, verbose syntax
val arr = Array(10) { 0 } // concise version
Or create an Array to avoid having to initialize every value, but then you'll be later forced to deal with possible null values every time you read from the array.
val arr = arrayOfNulls(10)