次のような抽象基本クラスを定義しました。
abstract class Base() {
val somevariables
}
そして、このクラスを次のように拡張します。
case class Derived (a: SomeOtherClass, i: Int) extends Base {
//Do something with a
}
次に、次のようなメソッド(クラスに依存しない)があります。
def myMethod (v1: Base, v2: Base, f:(Base, Base) => Int ): Int
そして、上記の方法を として使用したいのですがmyMethod(o1, o2, f1)
、
o1, o2
タイプのオブジェクトですDerived
f1
以下のとおりでありますdef f1(v1: Derived, v2: Derived): Int
関数が であり、 ではないことをmyMethod
期待しているため、エラーが発生します。ただし、 の定義を に変更すると、エラーが発生します。これは、内部的に を持たない引数である変数 from を使用したいためです。f1
(Base, Base) => Int
(Derived, Derived) => Int
f1
(Base, Base) => Int
SomeOtherClass
Base