Usages of Null / Nothing / Unit in Scala

后端 未结 8 1713
刺人心
刺人心 2020-11-30 18:34

I\'ve just read: http://oldfashionedsoftware.com/2008/08/20/a-post-about-nothing/

As far as I understand, Null is a trait and its only instance is

8条回答
  •  温柔的废话
    2020-11-30 19:26

    Nothing is often used implicitly. In the code below, val b: Boolean = if (1 > 2) false else throw new RuntimeException("error") the else clause is of type Nothing, which is a subclass of Boolean (as well as any other AnyVal). Thus, the whole assignment is valid to the compiler, although the else clause does not really return anything.

提交回复
热议问题