How do I get an instance of the type class associated with a context bound?
问题 Note: I'm posing this question to answer it myself, but other answers are welcome. Consider the following simple method: def add[T](x: T, y: T)(implicit num: Numeric[T]) = num.plus(x,y) I can rewrite this using a context bound as follows def add[T: Numeric](x: T, y: T) = ??.plus(x,y) but how do I get an instance of the Numeric[T] type so that I can invoke the plus method? 回答1: Using the implicitly method The most common and general approach is to use the implicitly method, defined in Predef: