Created
September 13, 2011 19:11
-
-
Save paulp/1214759 to your computer and use it in GitHub Desktop.
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
Razvan Cojocaru [email protected] | |
to [email protected] | |
date Tue, Sep 13, 2011 at 11:07 AM | |
subject [scala-user] unexpected REPL equals | |
The REPL unexpectedly calls equals with a String - this behavior is new in 2.9.1. – in the code below, I know the equals sucks but is short and used to work since 2.8 | |
What to do? What to do? | |
$ scala | |
Failed to created JLineReader: java.lang.NoClassDefFoundError: Could not initialize class org.fusesource.jansi.internal. | |
Kernel32 | |
Falling back to SimpleReader. | |
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> class Num (val i:Int) { | |
def + (other:Num) = new Num (this.i + other.i) // operators | |
override def toString : String = "Numero " + i.toString // inherit Java methods | |
override def equals (other:Any) = other.asInstanceOf[Num].i == i | |
} | |
| | | | defined class Num | |
scala> new Num(3) | |
java.lang.ClassCastException: java.lang.String cannot be cast to Num | |
at Num.equals(<console>:10) | |
at scala.runtime.ScalaRunTime$.inner$1(ScalaRunTime.scala:318) | |
at scala.runtime.ScalaRunTime$.stringOf(ScalaRunTime.scala:334) | |
at scala.runtime.ScalaRunTime$.replStringOf(ScalaRunTime.scala:341) | |
at .<init>(<console>:14) | |
at .<clinit>(<console>) | |
at $print(<console>) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | |
at java.lang.reflect.Method.invoke(Method.java:597) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment