Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '#' mean in a type parameter? [duplicate]

Possible Duplicate:
Why does one select Scala type members with a hash instead of a dot?

I sometimes see a type parameter like:

class Test[K] {
  type T = Foo[K#Bar]
}

Can someone please explain what the '#' means in this type parameter ? Is it some kind of restriction for K ?

like image 916
John Threepwood Avatar asked Oct 23 '22 16:10

John Threepwood


1 Answers

No, the # is a type projection. In your case however that does not work because K does not define any BAR type.

trait A  { 
           type T 
           def apply():T 
}

trait MyClass[X<:A] { 
               type SomeType = X#T 
               def applySeq():Traversable[SomeType] 
}


class AImpl extends A { 
      type T=Int 
      def apply():Int = 10
}

class MyClassImpl extends MyClass[AImpl] {
         def applySeq(): Traversable[SomeType] = List(10)
}

That basically let you use the type T in A inside MyClass .

In fact, also the following compile:

class MyClassImpl extends MyClass[AImpl] {def applySeq(): Traversable[Int] = List(10)}
like image 165
Edmondo1984 Avatar answered Oct 31 '22 14:10

Edmondo1984