【发布时间】:2020-06-16 08:57:08
【问题描述】:
考虑以下采用* -> * kind 类型参数的方法
def g[F[_]] = ???
为什么下面的不是语法错误
g[Any] // ok
g[Nothing] // ok
因为
scala> :kind -v Any
Any's kind is A
*
This is a proper type.
scala> :kind -v Nothing
Nothing's kind is A
*
This is a proper type.
所以Any 和Nothing 应该是错误的形状?
【问题讨论】:
-
我猜这两个是编译器产生的异常,因为 Any 和 Nothing 都是特殊的,并且在编译器无法推断出任何东西时使用否则。
标签: scala type-parameter type-constructor