When you have a parent:
abstract class Parent {
def something(arg: ???): Parent = ???
}
and
class Child extends Parent {}
I would like
val updatedChild = new Child().something(...)
updatedChild to be of type Child and not of type Parent, is it possible ?
One way to do it, is to parametrize the parent:
Sometimes, you can also get away with using
this.type:But the latter method only works if all you ever want to return is
this(this.typeis notParentorChild, but a specific type that only has one instance -this).