Search code examples
arraysscalanullread-eval-print-loopunit-type

Why can an Array of Units hold null?


Unit is specified to be a subtype of AnyVal (and its only value is ()), so why is this possible:

scala> val units = new Array[Unit](5)
units: Array[Unit] = Array(null, null, null, null, null)

Is this just a bug/omission in the REPL's array printing mechanism or is there a reason for it?


Solution

  • It was fixed for Scala 2.9 and now prints :

    scala> val units = new Array[Unit](5)
    units: Array[Unit] = Array((), (), (), (), ())