What you need???
scala> (4+"abc").getClass.getName res3: java.lang.String = java.lang.String scala> ("abc"+4).getClass.getName res5: java.lang.String = java.lang.String
Both are java.lang.String. I think Interactive Interpreter just says String not java.lang.String . But we have instances of java.lang.String.
("abc"+4): '+' is applied to java.lang.String, and returns java.lang.String. This is true both on Java and Scala.
(4+"abc") on Java: '+' is applied to java.lang.Integer, and returns java.lang.String.
(4+"abc") on Scala: '+' is applied to scala.Int, and returns String. '+(x: String)' is defined on scala.Int.
The output of Interactive Interpreter uses type String = java.lanag.String , which is defined on Predef.scala. Of course, the reverse is not defined.
It looks so dirty
I do not think so.
must be consistent so that they are always String
I do not think so. It is agreed.
java version "1.7.0_09"
Scala code version 2.9.2
source share