3

私は次のクラスを持っています:

abstract class Base {
  type T
  def myMethod: T
}

abstract class B extends Base {
  type T <: String
}

abstract class C extends Base {
  type T <: Int
}

今、私がこれを書くと:

class Test{
    self: B with C => 
    // do sth with myMethod
}

myMethod は Int 型の sth になります。一方、私がこれを書く場合:

class Test{
    self: C with B => 
    // do sth with myMethod
}

String 型を取得します。誰かがそれを説明できますか?

4

1 に答える 1

0

はい、できます!バグです!そして、Martin Odersky 自身によると、これは「Scala の型システムにおける根本的な問題」の結果です (議論については、その問題に関するコメントと、今朝のこの質問も参照してください)。

于 2013-08-20T10:40:23.270 に答える