Is it safe to assume that:

because scala.AnyRef defines toString() and hashCode() with a pair of parenthesis due to interoperability with Java (as suggested by Martin in: https://groups.google.com/forum/#!topic/scala-language/RlV9O1RDmis),

every single class in the Scala standard library that is a descendent of scala.AnyRef defines toString() and hashCode() with a pair of parenthesis ?

In other words, can I trust that the developers of the standard library were consistent in using toString() and hashCode() for the descendent classes of AnyRef?

Edit - changed the question to ask only for descendent classes of AnyRef

有帮助吗?

解决方案

Since all you need is one counterexample, here you go:

object Int extends AnyValCompanion {
  ...
  override def toString = "object scala.Int"
}

But grepping for "toString[^(]" on the standard library source turns up hundreds of others.

Note that the ability to override a method with an empty parameter list with a parameterless one was explicitly added to the Scala language specification in Scala 2.0.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top