说我有:
class Class[CC[A, B]]
class Thing[A, B <: Int]
class Test extends Class[Thing] // compile error here
我收到编译器错误:
kinds of the type arguments (cspsolver.Thing) do not conform to the expected kinds of the type parameters (type CC) in class Class. cspsolver.
Thing's type parameters do not match type CC's expected parameters: type C's bounds <: Int are stricter than type B's declared bounds >: Nothing <: Any
但是,当我修改代码时,它看起来像这样:
class Class[CC[A, B]]
class Thing[A, B] {
type B <: Int
}
class Test extends Class[Thing]
它编译得很好。它们在功能上不是等效的吗?
最佳答案
原因在编译器消息中给出。在 Class
你期望一个不受限制的CC
, 而 Thing
有第二个类型参数必须是 <: Int
的限制.一种可能性是将相同的约束添加到 Class
如
class Class[CC[A,B <: Int]]
class Thing[A, B <: Int]
class Test extends Class[Thing]
关于scala - 这种类型参数语法无法编译的原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18073160/