Nothing
1. 定义和用途
2. 特性
3. 示例
def fail(message: String): Nothing = {
throw new RuntimeException(message)
}
val result = fail("Something went wrong!") // result 类型为 Nothing4. 适用场景
Last updated
def fail(message: String): Nothing = {
throw new RuntimeException(message)
}
val result = fail("Something went wrong!") // result 类型为 NothingLast updated
def process(value: Any): String = value match {
case s: String => s"String: $s"
case i: Int => s"Integer: $i"
case _ => fail("Unsupported type") // 返回 Nothing
}