【发布时间】:2020-12-12 09:45:32
【问题描述】:
scala.Nothing 是没有该类型值的类型。
在 scala 中,“throw”表达式的类型为 Nothing,并且表达式的计算结果也是一个值。
这两个不矛盾吗?
【问题讨论】:
-
我认为区分
throw expressions has type Nothing和throw returns Nothing很重要,你是说后者吗? -
def error(message: String): Nothing = throw new RuntimeException(message) ....这段代码可能意味着 throw 表达式的类型为 Nothing。