abstract class A {
protected[this] type ThisType = this.type
protected[this] type OtherType = this.type
def assign(other: OtherType): ThisType
}
class B extends A {
def assign(other: OtherType): ThisType = ???
}
class C extends A {
def assign(other: OtherType): ThisType = ???
}
class D extends C {
def assign(other: OtherType): ThisType = ???
}
How do I make sure the other type received in assign
of and object of type B
is also B
. e.g. how can I write something effectively like:
def f1(p1: A, p2: A) = p1.assign(p2)
def f2[T <: A](p1: T, p2: T) = p1.assign(p2)
I am getting following errors:
NB: Actually ThisType
and OtherType
should be the same but I seperated them so I can try out different options.