trait MyTrait[A <: MyParentTrait]:
def myMethod: A = ... impl in trait ...
I have to have a type arg A with the only purpose that a call to myMethod returns the actual type extending MyTrait:
case class MyClassExt(...) extends MyParentTrait with MyTrait[MyClassExt]
Having the type arg A is complicated/hard to manage. Is there any way of having myMethod return MyClassExt (or whatever type extends MyTrait) without the type arg?
Thanks all, I ended up using the type This solution. I have more than 100 case classes (and more will be added in the future) and for a start it seemed the smallest change. Also not sure what 100+ implicits will do for compilation times if I ended up doing the type classes solution.
Anyway a few hours later I changed several traits that was using the trait X[A] pattern. It all works well and the code is simpler now. Only thing I have to declare type This on every case class, I suppose there is no shortcut to declare it on the parent trait like trait MyParentTrait: type This = this.class.type