Scala Language Symbol Literals

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


Scala comes with a concept of symbols - strings that are interned, that is: two symbols with the same name (the same character sequence), in contrary to strings, will refer to the same object during execution.

Symbols are a feature of many languages: Lisp, Ruby and Erlang and more, however in Scala they are of relatively small use. Good feature to have nevertheless.


Any literal beginning with a single quote ', followed by one or more digits, letters, or under‐scores _ is a symbol literal. The first character is an exception as it can’t be a digit.

Good definitions:


// Using the `Symbol.apply` method

Symbol("hakuna matata")
Symbol("To be or not to be that is a question")

Bad definitions:


Got any Scala Language Question?