I have the exact same question, mostly because I recall that Scala has primitive arrays hidden away. But Scala has a much more complicated type system as well.
This feels like a break in the design: Kotlin does not have the concept of primitive types, but wait, for arrays it does. So I agree with the OP: this should be hidden away more. The constructor Array()
could be overloaded for primitive/built-in types and construct, say, an IntArray
while exposing the type Array<Int>
.
@norswap Instead of special-casing everywhere, could you not box the whole array on demand? It’s clear that an IntArray
should only be used as Array<Int>
and not as Array<out Int>
, but why bother the programmer with that? But then, Kotlin does not have implicit boxing. Huh.
that’s the fault of the JVM rather than Kotlin, which just has to live with this complexity for now
That’s not a very good argument on its own. There definitely are other solutions (you mention Scala yourself).
presumably there will need to be some sort of new syntax to determine which it is
The compiler will have to figure out the details. Otherwise, keep clear.