8.5. Scala data type

发布时间 : 2025-10-25 13:35:10 UTC      

Page Views: 10 views

Scala and Java have the same data types, and the following table lists the data types supported by Scala:

Data type

Description

Byte

An 8-bit signed complement integer. Values range from-128 to 127

Short

A 16-bit signed complement integer. Values range from-32768 to 32767

Int

A 32-bit signed complement integer. Values range from-2147483648 to 2147483647

Long

64-bit signed complement integer. The range of values is-9223372036854775808 to 9223372036854775807

Float

32-bit, IEEE 754 standard single-precision floating-point number

Double

Double-precision floating-point numbers in 64-bit IEEE 754 standard

Char

16-bit unsigned Unicode characters with interval values from Ubun0000 to U+FFFF

String

Character sequence

Boolean

True or false

Unit

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

Null or null reference

Nothing

The Nothing type is at the bottom of the class level of Scala; it is a subtype of any other type.

Any

Any is the superclass of all other classes

AnyRef

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.

8.5.1. 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:

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。