开发者

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

开发者 https://www.devze.com 2023-04-08 18:52 出处:网络
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 i

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

精彩评论

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