What does the "#" in the type parameter mean?

Possible duplicate:
Why do you choose Scala elements with a hash instead of a period?

Sometimes I see a type parameter, for example:

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

Can someone explain what “#" means in a parameter of this type? Is this some kind of limitation for K?

+5
source share
2 answers

No, # is a type projection. In your case, however, this does not work because K does not determine the type of BAR.

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)
}

Basically, you can use type T inside MyClass.

In fact, also the following compiler:

class MyClassImpl extends MyClass[AImpl] {def applySeq(): Traversable[Int] = List(10)}
+3
source

'#' , . . " Scala " ?

0

All Articles