开发者

Scala: Constraining a generic type parameter to a type within another parameter

I'm still trying to grasp the Scala language, so please bear with me and all my questions.

Can I reference an abstract type from one type parameter in the bound for a开发者_如何学Pythonnother? For instance, is there a way in which the following code can be made to work? The essence of what I'm trying to achieve here is that the KEY for the MAP parameter of C should be the SomeType of the parameter T.

trait T1 { 
    type SomeType;
}

trait MyMap[KEY, VALUE] { ... }


class C { 
  def m[T <: T1, MAP <: MyMap[T.SomeType, Int]] { ... }
}    


You need type projection:

def m[T <: T1, MAP <: MyMap[T#SomeType, Int]]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜