Covariance and nullable

Take the definition of copyOf:

fun <T> Array<T>.copyOf(newSize: Int): Array<T?>

Why can it be called with a contravariant parameter (Array<in Number>), but not with a covariant parameter (Array<out Number>)?
The first will return Array<in Number?> whereas the second will issue Unsupported [Array<Nothing> in return type is illegal]

1 Like

This looks like some limitation in the type inference. Could you please report this case to

1 Like