I was under the impression that context bounds would work only on methods:
trait Target[T]
class Post {
def pinTo[T : Target](t:T)
}
apparently context bounds can be used in class
too (but not in trait
):
trait Target[T]
class Post[T: Target] {
def pintTo[T](t:T)
}
Now I'm confused as to how the evidence can be provided to Post
?
class Business
implicit object ev extends Target[Business] // is implicit necessary here ?
val p = new Post[Business] // ?? how do I provide ev ?
The
A: Foo
notation for context bounds is only a shortcut for asking for an implicit value parameter of typeFoo[A]
. Since traits do not have constructor value parameters, you can not use this with a trait:Whereas in classes it's possible:
Which is just a different way of writing
You provide the evidence like you do in any other normal method call:
Or: