i just noticed that Array.kt in kotlin 1.4.10 has ...
# announcements
a
i just noticed that Array.kt in kotlin 1.4.10 has an inline constructor but when I try to do it intellij says "Modifier is not applicable for constructor" why is this?
k
Build-in types like
Array<T>
are not implemented in Kotlin, but rather are mapped to platform types. Those files you are looking are not the actual definition of those types, but rather documentation. Build-in types are handled by the compiler differently compared to normal code. In your case, the compiler will perform whats known as an intrinsic. It will replace the call to the array constructor by inlining a function that looks a bit like this:
Copy code
inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
    val result = arrayOfNulls<T>(size)
    for (i in 0 until size) {
         result[i] = init(i)
    }
    return result as Array<T>
}
Generally speaking the compiler does not support the inlining of constructors. It only knows how to do it in this specific case, because it was programmed into the compiler as an intrinsic.
🙌 1