How to convert an Array<Int> into an IntArray?


#1

Hello,

I was wondering if there is an easy way to convert an Array<Int> into an IntArray? The background is that the array-helper returns an Array<Int>, but the function I have to call requires an IntArray.

fun test(values: IntArray) { ... } val values = array(1, 2, 3) test(values) // does not work

Kind regards, Philipp


#2

I think there should be such a function in the standard library, if there isn't, feel free to contribute or file an issue


#3

Ok, thanks. I'll check again.


#4

In your example you can just use intArray function. And for converting we don't have any function, and I create issue, feel free to vote and/or contribute.


#5

Great! intArray was what I was looking for. Thanks


#6

I had a look into the code when looking at the described problem and in Array.kt I found this:

public class Array<reified T>( ...) { }

I wonder what the meaning of reified is. Are there any plans about reified types?

Regards, Oliver


#7

This simply reflects the nature of JVM arrays which are indeed reified