由适当类型界定的类型构造函数

问题描述 投票:1回答:1

请考虑以下类型参数子句[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 ...>

scala type-constraints type-constructor
1个回答
0
投票

类型参数声明F[_] <: Int意味着F的每个实例

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.