I’m not familiar with Scala and come across this problem below when using interactive mode:
scala>"abc"+4
res0: java.lang.String = abc4
scala>4+"abc"
res1: String = 4abc
What I’m curious about is that how the type of the result can be different(java.lang.String vs String). And in Book Seven Languages in Seven Weeks the two types are both java.lang.String.
BTW,the version of scala interpreter is 2.9.1.
On the JVM, scala’s
Stringis just an alias tojava.lang.String. The fact that the Repl sometimes displays the type asStringand sometimes asjava.lang.Stringis just a minor (REPL specific) glitch that does not affect in any way the runtime behaviour.For what it’s worth, here is what I get in scala 2.10-RC1: