请考虑以下类型参数子句[F[_] <: Int]
:>
def h[F[_] <: Int] = ???
其中类型构造函数
F
由适当的类型Int
界定。现在h[List]
和h[Int]
都是非法的
scala> def h[F[_] <: Int] = ??? | def h[F[_] <: Int]: Nothing scala> h[List] ^ error: type arguments [List] do not conform to method h's type parameter bounds [F[_] <: Int] scala> h[Int] ^ error: Int takes no type parameters, expected: 1
那么
[F[_] <: Int]
为什么是合法的?
请考虑以下类型参数子句[F [_] <: int in def h where a type constructor f is bounded by the proper int. now both and are illegal ...>
类型参数声明F[_] <: Int
意味着F
的每个实例