https://kotlinlang.org logo
#stdlib
Title
# stdlib
j

jw

05/20/2019, 7:07 PM
Array.copyOf
returns an array which retains the variance. I.e.,
Array<out String>
stays as
out String
despite me taking a copy to modify its contents. Right now I'm just doing an unsafe cast, but it feels unfortunate (even more than how unfortunate it is to already be using arrays 😢 )
i

ilya.gorbunov

05/21/2019, 2:11 AM
That's how
copyOf
behaves on JVM: it preserves the actual element type of the original array in the new array. So if it was an array of some
StringSubtype
the copy remains an array of the same subtype and we can't treat it as an invariant array of
String
.
2 Views