Scala data type
Scala and Java have the same data types, and the following table lists the data types supported by Scala:
Data type |
Description |
---|---|
|
An 8-bit signed complement integer. Values range from-128 to 127 |
|
A 16-bit signed complement integer. Values range from-32768 to 32767 |
|
A 32-bit signed complement integer. Values range from-2147483648 to 2147483647 |
|
64-bit signed complement integer. The range of values is-9223372036854775808 to 9223372036854775807 |
|
32-bit, IEEE 754 standard single-precision floating-point number |
|
Double-precision floating-point numbers in 64-bit IEEE 754 standard |
|
16-bit unsigned Unicode characters with interval values from Ubun0000 to U+FFFF |
|
Character sequence |
|
True or false |
|
It means no value, which is equivalent to void in other languages. The result type used as a method that returns no results. Unit has only one instance value, written as (). |
|
Null or null reference |
|
The Nothing type is at the bottom of the class level of Scala; it is a subtype of any other type. |
|
Any is the superclass of all other classes |
|
The AnyRef class is the base class for all reference classes (reference class) in Scala |
The data types listed in the above table are all objects, which means that scala does not have native types in java. In scala, you can call methods on basic types such as numbers.
Scala basic literals
Scala is very simple and intuitive. Next we will introduce the literals of Scala in more detail.
Integer literal quantity
Integer literals are used for Int
type, if it represents the Long
,you can add an L or a lowercase l after the number as a suffix :
0
035
21
0xFFFFFFFF
0777L
Floating point literal quantity
If a floating point number is followed by an f or F suffix, it means that this is a Float
type, otherwise it is a Double
type. Examples are as follows:
0.0
1e30f
3.14159f
1.0e100
.1
Boolean literal quantity
Boolean literal quantity true
and false
.
Symbolic literal quantity
The literal amount of the symbol is written as:’< identifier >, where < identifier > can be the identity of any letter or number (note: it cannot start with a number). This literal quantity is mapped to a predefined class. scala.Symbol
example.
For example, the literal quantity of symbols 'x
is an expression. scala.Symbol("x")
the literal quantity of the symbol is defined as follows: