blob: ea8eb2b547cbc0463841935f699cac1d751b49b8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
trait Comparator {
type T // abstract type member, to be filled in by concrete classes
def ordering: Ordering[T]
def compare(a: T, b: T): Int = ordering.compare(a, b)
}
object IntComparator extends Comparator {
type T = Int
def ordering: Ordering[Int] = Ordering.Int
}
object Test {
def process(c: Comparator)(items: Seq[c.T]): Int = {
c.compare(items(0), items(1))
}
}
class Processor[K](c: Comparator { type T = K }) {
def process(items: Seq[K]): Int = {
c.compare(items(0), items(1))
}
}
|