Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Comments

  1. An array in Java is not an Iterable (due to design reasons). There is no super class of array and Iterable either in Java. If you want a method to support both array and Iterable as the parameter, you need to overload it (for both array and Iterable.) It is the same situation in Kotlin as Kotlin is mostly Java.

IntArray vs Array in Kotlin

Array is an Integer[] under the hood while IntArray is an int[].

IntArray(5)
[0, 0, 0, 0, 0]
IntArray(5, {
    i: Int -> i
})
[0, 1, 2, 3, 4]
intArrayOf(10, 20, 30)
[10, 20, 30]

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.