Literals
In the previous discussion, we've seen a String literal and an Integer too. Here, we'll discuss all available literals, and how to define them in Scala. If you're coming from a Java background, then quite a few will be the same for you: Integer, Floating point, Boolean, Character, and String are similar. Along with those, the Tuple and Function literals can be treated as something new to learn. All the literals are listed as follows:
- Integer literals
- Floating point literals
- Boolean literals
- Character literals
- String literals
- Symbol literals
- Tuple literals
- Function literals
We'll discuss them one by one. Let's start with Integer literals.
Integer literals
Numeric literals can be expressed in the form of decimal, octal, or hexadecimal forms. These are basic integer values that can be signed or unsigned. Octal values are deprecated since version 2.10, so if you try out a numeric with a leading 0
, it'll give you a compile time error:
scala> val num = 002 <console>:1: error: Decimal integer...