这是对方法==和值null的正确重新定义吗?

时间:2016-11-02 04:20:30

标签: scala

根据Scala Language Specification,我们有

abstract class Any {
  ...
  final def == (that: Any): Boolean  =
      if (null eq this) null eq that else this equals that
  ...
}

abstract final class Null extends AnyRef

我的问题是上述内容是否等同于以下重构:

abstract class Any {
  ...
  final def == = equals
  ...
}

case object null extends AnyRef {
  override def equals(that: Any): Boolean = that match {
    case that: AnyRef => null eq that
    case _ => false
  }
}

0 个答案:

没有答案