Created
June 18, 2010 02:00
-
-
Save rossabaker/443103 to your computer and use it in GitHub Desktop.
Scala equality pitfall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> null == 42 | |
res0: Boolean = false | |
scala> (null:java.lang.Integer) == 42 | |
java.lang.NullPointerException | |
at scala.runtime.BoxesRunTime.equalsNumNum(Unknown Source) | |
at scala.runtime.BoxesRunTime.equalsNumObject(Unknown Source) | |
at .<init>(<console>:6) | |
at .<clinit>(<console>) | |
at RequestResult$.<init>(<console>:9) | |
at RequestResult$.<clinit>(<console>) | |
at RequestResult$scala_repl_result(<console>) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:616) | |
at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$18.apply(Interpreter.scala:981) | |
at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I posted the equality problem to the Scala mailing list, and within a couple hours, a fix was committed. Hooray for Paul Phillips and the rest of the Scala dev team.
http://scala-programming-language.1934581.n4.nabble.com/and-equals-td2261488.html#a2262102
http://lampsvn.epfl.ch/trac/scala/changeset/22379/