-> 我们怎样才能write a scala method
其返回类型为 Nothing
?
-> 我们ever need to write such methods
?有没有useful scenarios
?
最佳答案
您实际上无法返回 Nothing
类型的值因为没有 Nothing
类型的值.所以定义一个返回类型函数的唯一方法 Nothing
是永远不会回来。
一个例子是一个无限递归地调用自己的函数。另一种是总是抛出异常或简单地退出应用程序( sys.exit
的返回类型是 Nothing
)。
关于scala - 编写一个不返回任何内容的 Scala 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37739628/