Thread
#stdlib
    j

    jw

    3 years ago
    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 😢 )
    ilya.gorbunov

    ilya.gorbunov

    3 years ago
    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
    .