Comments¶
- An array in Java is not an
Iterable(due to design reasons). There is no super class of array andIterableeither in Java. If you want a method to support both array andIterableas the parameter, you need to overload it (for both array andIterable.) It is the same situation in Kotlin as Kotlin is mostly Java.
IntArray vs Array in Kotlin
Array
In [1]:
IntArray(5)
Out[1]:
In [2]:
IntArray(5, {
i: Int -> i
})
Out[2]:
In [1]:
intArrayOf(10, 20, 30)
Out[1]:
Array is NOT Iterable!¶
Array in Kotlin is not Iterable (similar to that in Java).
However,
you can call the asIterable to make convert it to an Iterable object.
Or you can return a List object by calling the method toList.
In [ ]: