Pattern: Use of Array<Primitive>
Issue: -
Using Array<Primitive>
leads to implicit boxing and performance hit. Prefer using Kotlin specialized Array
Instances.
As stated in the documention, Kotlin has
specialized arrays to represent primitive types without boxing overhead, such as IntArray
, ByteArray
and so on.
Example of incorrect code:
fun function(array: Array<Int>) { }
fun returningFunction(): Array<Double> { }
Example of correct code:
fun function(array: IntArray) { }
fun returningFunction(): DoubleArray { }