Is there a way to define a type Tin Parent in such a way that it Talways becomes the actual type of an expanding class (in this case Child)?
In ParentI want to force / declare to Talways be an extensible type, as if I wrote type T="type_of_the_extending_class"in every valid extending class, without actually writing the lines type T=Child1to Child1, etc.
Thus, the Child1 method should accept Child1 objects as a parameter, and the Child2 method should only accept Child2 objects. Is there an easier way to provide this? Is there a way without recording type T=ChildXin each class ChildX? Is there any way without this template?
I searched for a solution in Scala books, but could not find.
abstract class Parent{
type T<:Parent
def method(t:T)
}
class Child1 extends Parent{
type T=Child1
override def method(t:T)=t.child1method
def child1method=println("child1 method")
}
class Child2 extends Parent{
type T=Child2
override def method(t:T)=t.child2method
def child2method=println("child2 method")
}