Why does an array of type Int have its entries initialised to 0, but an array of type BigInt have its entries initialised to null?
val a = new Array[Int](1)
val b = new Array[BigInt](1)
println(a.mkString())
println(b.mkString())
yields
0
null
According to the scaladoc for Int:
Instances of Int are not represented by an object in the underlying runtime system.
Looking at the compiled class file, it indeed shows that the array of Ints becomes an array of int primitives in the bytecode. And int primitives have a value of 0 by default.
0 iconst_1
1 newarray int [10]
3 astore_2 [a]
4 iconst_1
5 anewarray scala.math.BigInt [16]
new Array[T](len)is a discouraged way to use arrays in scala. (probably, because it may lead to all sorts of confusion, as you shown in this question).