If an Array [Double] array containing all zeros is required, is it safe to use
val allZeros = new Array[Double](10)
val whatever = allZeros( 5 )
assert( whatever == 0.0 )
or should i stick
val allZeros = Array.fill[Double](10)( 0.0 )
I know that the first version works, but is this a guarantee that the language makes, i.e. will she always be safe? A double can theoretically also be initialized null(although thinking about it as a language developer, I would prefer not to make such a change :-).
source
share