IntArray vs Array<Int> in Kotlin

Viewed 30193

I'm not sure what the difference between an IntArray and an Array<Int> is in Kotlin and why I can't used them interchangeably:

missmatch

I know that IntArray translates to int[] when targeting the JVM, but what does Array<Int> translate to?

Also, you can also have String[] or YourObject[]. Why Kotlin has classes of the type {primitive}Array when pretty much anything can be arranged into an array, not only primitives.

3 Answers

It is worth noting that using the spread (*) operator on a vararg will return an IntArray. If you need an Array<Int>, you can convert your IntArray using .toTypedArray().

Related