Eyvind
Eyvind

Reputation: 5261

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 another? 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]] { ... }
}    

Upvotes: 3

Views: 232

Answers (1)

kiritsuku
kiritsuku

Reputation: 53348

You need type projection:

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

Upvotes: 6

Related Questions