Essentially, I am trying to do the following:
trait Foo[T] extends T {
def json: Writes[T]
def bar: String = {
Json.toJson[T](this)(json).toString
}
}
I want the compiler to enforce that any class using trait Foo is of type T. Unfortunatly, 'extends T' is not valid. Right now, the best I can do is the following:
trait Foo[T] extends T {
def json: Writes[T]
def bar: String = {
Json.toJson(this.asInstanceOf[T])(json).toString
}
}
But obviously, the compiler isn't enforcing anything. Is there anyway to achieve what I want?