1

Possible Duplicate:
Practical examples of using symbols in Scala?

What is the reason of having symbols in Scala if strings are immutable? After what I know symbols are used when the identity is important, this means that the symbols are interned and two symbols with the same character value would be the same object. But isn't this already done to strings in Scala if the strings are from the Java language (where they are immutable and interned)?

If I have misunderstood symbols or you can provide more information about why they are needed/used I would be happy to learn:)

Community
  • 1
  • 1
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
  • Java strings are not necessarily interned. String literals are. `"this is upper case".toUpperCase()` is not. – Ed Staub Mar 01 '12 at 18:36

1 Answers1

1

I would say the opposite : symbols are used when only the identity is important. Two symbols with the same name will always refer to the same instance, so these references can be compared without risk.

Symbols can be used, for example, as a lightweight enum.

barjak
  • 10,842
  • 3
  • 33
  • 47