File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ trait Comparator {
2
+ type T // abstract type member, to be filled in by concrete classes
3
+ def ordering : Ordering [T ]
4
+ def compare (a : T , b : T ): Int = ordering.compare(a, b)
5
+ }
6
+
7
+ object IntComparator extends Comparator {
8
+ type T = Int
9
+ def ordering : Ordering [Int ] = Ordering .Int
10
+ }
11
+ object Test {
12
+ def process (c : Comparator )(items : Seq [c.T ]): Int = {
13
+ c.compare(items(0 ), items(1 ))
14
+ }
15
+ }
16
+ class Processor [K ](c : Comparator { type T = K }) {
17
+ def process (items : Seq [K ]): Int = {
18
+ c.compare(items(0 ), items(1 ))
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ final class Foo (val x : String ) extends AnyVal { override def toString = " " + x }
3
+ final class Bar (val f : Foo ) extends AnyVal { override def toString = " " + f }
4
+ def main (args : Array [String ]) = {
5
+ val x = " abc"
6
+ val f = new Foo (x)
7
+ val b = new Bar (f)
8
+ assert(b.toString == " abc" )
9
+ }
10
+ }
You can’t perform that action at this time.
0 commit comments