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?
case class Foo[A](i: MyTrait[A])?ifrom that in a matcher and try to pass theitoMyTrait.doSomething[T<:MyTrait[T]](aninstance:T), I get an error: "inferred type arguments [MyTrait[Any]] do not conform to method doSomething's type parameter bounds [T <: MyTrait[T]]"case class Foo[A <: MyTrait[A]](i:MyTrait[A])I still get the same inferred type arguments error when trying to pass theitodoSomething