Why are Arrays invariant, but Lists covariant?

Because it would break type-safety otherwise.
If not, you would be able to do something like this:

val arr:Array[Int] = Array[Int](1,2,3)
val arr2:Array[Any] = arr
arr2(0) = 2.54

and the compiler can’t catch it.

On the other hand, lists are immutable, so you can’t add something that is not Int

Leave a Comment