diff options
author | Martin Odersky <odersky@gmail.com> | 2004-04-23 14:11:16 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2004-04-23 14:11:16 +0000 |
commit | 92fcc53be94a107f3b560b855564bc39ba8f2372 (patch) | |
tree | c1b8e40ef4d21e18741b9f286d6e9047d39cc44e /test/files/pos/orderedpoints.scala | |
parent | abe707d00a280e8f33cbc2a064cb970460c19d7d (diff) | |
download | scala-92fcc53be94a107f3b560b855564bc39ba8f2372.tar.gz scala-92fcc53be94a107f3b560b855564bc39ba8f2372.tar.bz2 scala-92fcc53be94a107f3b560b855564bc39ba8f2372.zip |
*** empty log message ***
Diffstat (limited to 'test/files/pos/orderedpoints.scala')
-rwxr-xr-x | test/files/pos/orderedpoints.scala | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/files/pos/orderedpoints.scala b/test/files/pos/orderedpoints.scala new file mode 100755 index 0000000000..145b0a8312 --- /dev/null +++ b/test/files/pos/orderedpoints.scala @@ -0,0 +1,26 @@ +class Point1(x: int) extends Object with Ordered[Point1] { + val xCoord = x; + def compareTo [b >: Point1 <% Ordered[b]](that: b): int = that match { + case that1: Point1 => this.xCoord.compareTo(that1.xCoord) + case _ => -that.compareTo(this) + } +} +class Point2(x: int, y: int) extends Point1(x) with Ordered[Point2] { + val yCoord = y; + def compareTo [b >: Point2 <% Ordered[b]](that: b): int = that match { + case that1: Point2 => + val r = super.compareTo(that1); + if (r == 0) this.yCoord.compareTo(that1.yCoord) else r + case _ => -that.compareTo(this) + } +} +object Test with Application { + val p1 = new Point1(1); + val q1 = new Point1(2); + System.out.println(p1 < q1); + val p2 = new Point2(1, 2); + val q2 = new Point2(1, 3); + System.out.println(p2 < q2); + System.out.println(p1 < q2); + System.out.println(p2 < q1); +} |