Why can I compare an Int and a String in Scala with ==, like 1=="2", even when this Operator is not defined for a String in the API (http://www.scala-lang.org/api/2.11.8/index.html#scala.Int)?
-
Note that the compiler will warn you: "warning: comparing values of types Int and String using `==' will always yield false". There are a number of ways to prevent comparisons of unequal types altogether. For example scalautils.org ; I also wrote a small macro: github.com/Sciss/Equal0__– 0__2016-05-02 23:26:49 +00:00Commented May 2, 2016 at 23:26
Add a comment
|
1 Answer
Because it's defined in Any: def ==(arg0: Any): Boolean
Test two objects for equality. The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that).
1 Comment
Luigi Plinge
To see this in the docs, you need to click Inherited: "Any" at the top of the scaladoc. For clarity, it's de-selected by default.