我的印象是上下文边界只适用于方法:
trait Target[T]
class Post {
def pinTo[T : Target](t:T)
}
Run Code Online (Sandbox Code Playgroud)
显然,上下文界限也可用于class(并且可能trait):
trait Target[T]
class Post[T:Target] {
def pintTo[T](t:T)
}
Run Code Online (Sandbox Code Playgroud)
现在我对如何提供证据感到困惑Post?
class Business
implicit object ev extends Target[Business] // is implicit necessary here ?
val p = new Post[Business] // ?? how do I provide ev ?
Run Code Online (Sandbox Code Playgroud)