summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeoffrey Washburn <geoffrey.washburn@epfl.ch>2008-02-27 15:53:44 +0000
committerGeoffrey Washburn <geoffrey.washburn@epfl.ch>2008-02-27 15:53:44 +0000
commitd650015537c350b151755c90aea2e62d3722828d (patch)
tree154c97b9ae0fbfa202475bc4cb9cc9d28b3f7446 /src
parent3b35b45b6f34aad38acbbf958de056181a785ddc (diff)
downloadscala-d650015537c350b151755c90aea2e62d3722828d.tar.gz
scala-d650015537c350b151755c90aea2e62d3722828d.tar.bz2
scala-d650015537c350b151755c90aea2e62d3722828d.zip
Add default implementations of equals and hashC...
Add default implementations of equals and hashCode to Ordered, along with an explanation that end users should override them if they plan on using them.
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/Ordered.scala22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/library/scala/Ordered.scala b/src/library/scala/Ordered.scala
index 9b0b49add6..ed9c34315b 100644
--- a/src/library/scala/Ordered.scala
+++ b/src/library/scala/Ordered.scala
@@ -33,4 +33,26 @@ trait Ordered[A] {
def <= (that: A): Boolean = (this compare that) <= 0
def >= (that: A): Boolean = (this compare that) >= 0
def compareTo(that: A): Int = compare(that)
+
+ /** It is important that the equals method for an instance of
+ * Ordered[A] be consistent with the compare method. However,
+ * due to limitations inherent in the type erasure semantics,
+ * there is no reasonable way to provide a default implementation
+ * of equality for instances of Ordered[A]. Therefore, if you need
+ * to be able to use equality on an instance of Ordered[A] you must
+ * provide it yourself either when inheiriting or instantiating.
+ * Therefore, the default implementation will fail with an error to
+ * prevent you from forgetting to do so. */
+ override def equals(other : Any) : Boolean =
+ error("You must implement equals for Ordered yourself.")
+
+ /** It is important that the hashCode method for an instance of
+ * Ordered[A] be consistent with the compare method. However,
+ * it is not possible to provide a sensible default implementation.
+ * Therefore, if you need to be able compute the hash of an
+ * instance of Ordered[A] you must provide it yourself either when
+ * inheiriting or instantiating. Therefore, the default implementation
+ * will fail with an error to prevent you from forgetting to do so. */
+ override def hashCode : Int =
+ error("You must implement hashCode for Ordered yourself.")
}