次の定義があるとします。
abstract class A
class B extends A
trait Test[T <: A] {
def foo(t: T) = println("I'm Foo")
def bar(t: T) = t match {
case b: B => foo(b)
case _ => println("Bar says: Other")
}
}
Scala コンパイラーは次のエラーを出します。
<console>:14: error: type mismatch;
found : b.type (with underlying type B)
required: T
case b: B => foo(b)
^
bvariable は type と同じオブジェクトでtあり、ttypeであるため、ここで何が問題なのかわかりませんT。
あるいは、コンパイラは variablebを新しいものと見なします ( との関係はありませんt)。次に、bは のサブタイプですが、 の任意のサブタイプになる可能性があるためA、 のサブタイプである必要はありません。これは正しい説明ですか?TTA