eq compares memory references.
String literals are placed in a string constant pool, so in the first example they use the same memory reference. This is a behavior that comes from Java ( scala.Stringbuilt on top java.lang.String).
In the second example, you allocate two instances at runtime, so when you compare them, they are in different places in memory.
This is exactly the same as Java, so you can refer to this answer for more information: What is the difference between the text? and new String ("text")?
, ( ), == ( equals) Scala.
:
val a = new String("Hello")
val b = new String("Hello")
a eq b
a == b
a equals b
Java, == - , eq Scala.
, == equals null (==). : == .equals Scala?