【发布时间】:2015-12-13 13:13:07
【问题描述】:
我为A 类写了一个equals 方法。
class A(x: Int, s: String) {
override def equals(that: Any) = that match {
case a: A => this.x == a.x && this.s == a.s
case _ => false
}
}
对吗?
【问题讨论】:
-
我刚刚发布了另一个问题的答案,这是对您问题的更详细的答案。对于您的类实例来说,正确实现
equals和hashCode以在Scala 集合库中正常运行至关重要。或者遭受意想不到的失败。 stackoverflow.com/a/56509518/501113
标签: scala