There are 2 things going on here. First of all Long
does not extend Ordering[Long]
. The page you linked from the docs in the comments is the documentation of an implicit object called Long
in the scala.math.Ordering
package.
However, that object is very relevant here. Since that object is in implicit scope, you can use a context bound to ensure that there is an instance of Ordered[Long]
is available, which will allow code to order your Longs
.
case class Key[K : Ordering](key: K)
This will allow you to do Key(1L)
.
Your other problem is that Long
is also not Serializable
, so the second generic parameter is also problematic. Long
is implicitly viewable as a java.io.Serializable
, which might be of interest to you here. You can use a view bound to ensure that K
and V
have this constraint:
type JS = java.io.Serializable
case class KVPair[K <% JS : Ordering, V <% JS](key: K, value: V)
The context-bound and view-bound syntax make this equivalent to:
case class KVPair[K, V](key: K, value: V)(
implicit kev1: Ordering[K],
kev2: K => JS,
vev1: V => JS
)
You can read more about context bounds and view bounds on this answer.