Scala Language Symbol Literals

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

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.

Use:

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:

'ATM
'IPv4
'IPv6
'map_to_operations
'data_format_2006

// Using the `Symbol.apply` method

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

Bad definitions:

'8'th_division
'94_pattern
'bad-format


Got any Scala Language Question?