Rob Elliot
02/22/2022, 8:46 AMkotlin.Array<E>
doesn't implement kotlin.collections.Iterable<E>
? They both define public operator fun iterator(): Iterator<E>
.
I know Java arrays don't, but does that limit Kotlin ones?
(I've often thought it would be convenient if Array<E> : FixedLengthMutableList<E>
& FixedLengthMutableList<E> : List<E>
, if that could all be done synthetically at compile time - is it reflection that prevents this? If so another reason to loathe reflection...)Rob Elliot
02/22/2022, 8:50 AMArray
implement a collections interface. Be interested to know what they are.dmitriy.novozhilov
02/22/2022, 8:51 AMkotlin.Array<E>
is replaced by javas E[]
, which can not be somehow modified by Kotlin, so Kotlin inherit all contracts and limitations for arrays from JavaRob Elliot
02/22/2022, 8:55 AMArray
to be typed as an Iterable
you'd have to do a runtime check every time you passed an Iterable
to a non-Kotlin method in case it were an Array
, in which case it would need to be boxed using Arrays.listOf
.dmitriy.novozhilov
02/22/2022, 9:00 AMByteArray
and IO)
2. Low-level implementation for actual collections
For everything else, there's array.toList()
Rob Elliot
02/22/2022, 9:04 AMSet
& List
, you could just use toSet
and toList
whenever you need to convert between them, but when all you want to do is iterate over them it's nice not to have to do that. There are loads of Java APIs that are still array based.