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?

15
задан Community 23 May 2017 в 12:15
поделиться