title: Reference equality for java.lang.String in Scala
body: <p>One would expect that even though strings are immutable, value-equality and reference-equality would not be the same for java.lang.String objects in Scala. This means that two string-holding <code>val</code>s should not be reference-equal even when their strings are identical. But here's what I get in a 2.9.1.final REPL:</p>
  
  <pre><code>scala&gt; val s1 = "a"; val s2 = "a"
  s1: java.lang.String = a
  s2: java.lang.String = a
  
  scala&gt; s1 eq s2
  res0: Boolean = true
  </code></pre>
  
  <p>Any idea why the result was not <code>false</code>? The same experiment with <code>List("a")</code> instead of <code>"a"</code> works as expected. The <code>eq</code> method is marked as final in <a href="http://www.scala-lang.org/api/current/scala/AnyRef.html" rel="noreferrer">AnyRef</a>. Is there any compiler magic done specifically for <code>String</code> or <code>java.lang.String</code>?</p>