Difference between ByteArray and Array<Byte> in kotlin Difference between ByteArray and Array<Byte> in kotlin arrays arrays

Difference between ByteArray and Array<Byte> in kotlin


Due to Java's limitations, Kotlin has 9 array types: Array<...> for arrays of references (in the JVM sense) and 8 specialized array types, i.e. IntArray, ByteArray etc.

https://kotlinlang.org/docs/reference/java-interop.html#java-arrays

The main reason for this distinction is performance: if we didn't specialize arrays it'd lead to a lot of boxing/unboxing and make arrays slow. This would be unacceptable because the only reason one might want to prefer arrays over collections is performance.


Said in short, just for future reference.

ByteArray equals byte[] in Java
Array<Byte> equals Byte[] in Java

No benefit from using one over the other in Kotlin, only if the code is to be parsed to Java.