我很乐意为您澄清一些关于“Unit”和“Nothing”的细节问题。以下是一个示例:
例如:
根据文档,Scala中的
例如:
def unit(companyId: Int): Unit = {}
def Nothing(companyId: Int): scala.Nothing = {}
根据文档,Scala中的
Unit
与Java中的void
非常相似。但是。test("test Unit and Nothing") {
println(unit(1))
}
Unit
返回-()
Nothing
不返回任何内容。
为什么Scala有一个溢出类型的Unit
,它返回Nothing
?
为什么Scala不能使用Nothing
代替Unit
?