When I declare class Pair[T : Ordering]
, it requires that there is an implicit value of Ordering[T]
. In the example below, I am trying to figure out where the implicit value of Ordering[Int]
is coming from.
It looks like scala.math.Ordering.Int
should be the implicit value here, but it has not been imported, so where is the implicit value being gotten from?
class Pair[T : Ordering](val first: T, val second: T) {
def smaller(implicit ord: Ordering[T]) =
if(ord.compare(first, second) < 0) first else second
}
object Run extends App {
val p = new Pair[Int](2, 3)
}