trait B {
type MyInnerType
def foo: MyInnerType
}
object B1 extends B {
type MyInnerType = Double
val foo = 3.0
}
trait A {
type MyInnerType
val b: B
def foo(x: b.MyInnerType): MyInnerType
def bar(y: MyInnerType): Unit
}
object A1 extends A {
type MyInnerType = Int
val b = B1
def foo(x: b.MyInnerType) = 1
def bar(y: MyInnerType) {}
}
object A2 extends A {
type MyInnerType = String
val b = B1
def foo(x: b.MyInnerType) = "a"
def bar(y: MyInnerType) {}
}
val as = Seq(A1, A2)
as foreach { a => a.bar(a.foo(a.b.foo)) } // wrong, a.foo(a.b.foo) infers to Any
ただし、a.foo
パラメータを受け取らない場合は、すべてが完全に機能し、をa.foo
推測しa.MyInnerType
ます。キャストしても動作し.asInstanceOf[a.MyInnerType]
ます。説明はありますか?