2012-07-11 118 views

回答

3

不,#是一個類型投影。在你的情況下,但不起作用,因爲K沒有定義任何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) 
} 

基本上可以讓你在MyClass裏面使用A的類型T.

事實上,還有如下編譯:

class MyClassImpl extends MyClass[AImpl] {def applySeq(): Traversable[Int] = List(10)} 
相關問題