I'm getting a type mismatch error trying to spread...
# getting-started
i
I'm getting a type mismatch error trying to spread an array of Ints. Am I'm doing something wrong, or is this a type inference limitation or bug?
Copy code
fun main(args: Array<String>) {
	val ints = arrayOf(1, 2, 3)
	// Type mismatch: inferred type is Array<Int> but IntArray was expected?
	spreadTest(*ints)
}

fun spreadTest(vararg ints: Int) {
	for (int in ints) {
		println(int)
	}
}
p
use intArrayOf() if you want to have an IntArray
👍 1
i
Ah, okay, so it's a limitation of the spread operator: https://youtrack.jetbrains.com/issue/KT-6846
Just for the record,
spreadTest(*ints.toIntArray())
also works, though I imagine not as efficient as starting out with
intArrayOf()
.