OK, so, I get that I can do things like:
trait MyTrait[T <: MyTrait[T]] { self: T =>
val listOfT: List[T]
def getFirst: T
def getOne: T = if (listOfT.length > 0) getFirst else self
}
class MyClass extends MyTrait[MyClass] {
override val listOfT: List[MyClass] = List[MyClass](this)
override def getFirst: MyClass = listOfT.head
}
and that if I want MyTrait to have a companion object it looks like:
object MyTrait{
def doSomething[T <: MyTrait[T]](aninstance:T)= { ... }
}
All that seems ugly and I’d like to see a nicer way, but, right now I’m just trying to figure out, how do I refer to the type from anywhere else? For example:
case class Foo( anInstanceOfMyTrait: MyTrait[what goes here???] )
Or is there a simpler way?
I got this to work: