In the absence of an explicit else
, Scala assumes this:
else ()
Where ()
is the value of Unit
. It's the value returned by println
or assignment to var
, for example.
This can be easily verified:
scala> val x = if (false) 1
x: AnyVal = ()
scala> x.isInstanceOf[Unit]
res3: Boolean = true