gpt4 book ai didi

scala - 为什么我不能将 Nothing 分配给 Unit 类型的变量?

转载 作者:行者123 更新时间:2023-12-02 05:41:44 26 4
gpt4 key购买 nike

如果 NothingAnyVal 的子类,包括 Unit,那么为什么我不能将 Nothing 分配给

import scala.Nothing
val oh: Unit = Nothing

最佳答案

就在scaladoc .

Nothing is a subtype of every other type (including scala.Null); there exist no instances of this type.

如果没有 Nothing 的实例,则不能将其分配给任何东西。这不是一个值。

关于scala - 为什么我不能将 Nothing 分配给 Unit 类型的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29463148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com