我试图写一个简单的工具斯卡拉通用上限
def withParLevel[T, Col <: ParIterable[T]](coll: Col, ts: TaskSupport): Col = {
coll.tasksupport = ts
coll
}
withParLevel(List(1,2,3,4,5).par, blockingPool)
这给了我这个错误:
inferred type arguments [Nothing,scala.collection.parallel.immutable.ParSeq[Int]] do not conform to method withParLevel's type parameter bounds [T,Col <: scala.collection.parallel.ParIterable[T]]
我该如何解决呢?
为什么它推断T为Nothing,而不是Int?
PS scala版本2.10.2
好奇,我不知道为什么类型推断在这里失败。我会等待有人解释这一点。与此同时,将它改为通配符('[T <:ParIterable [_]])或视图绑定('[A,B <%ParIterable [A]]')似乎可行... –
I' d完全删除'Col'类型参数并使用子类型多形主义:'def withParLevel [T](coll:ParIterable [T]):ParIterable [T] = coll' –