Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the purpose of the Scala data type

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

What is the role of the Scala data type, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

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

The data type describes Byte8-bit signed complement integers. The value range is from-128 to 127Short16 bit signed complement integers. Values range from-32768 to 32767Int32 bit signed complement integers. Values range from-2147483648 to 2147483647Long64 bit signed complement integers. The range of values is from-9223372036854775808 to 9223372036854775807Float32 bit, single-precision floating-point number Double64 bit of IEEE 754 standard double-precision floating-point number Char16 bit unsigned Unicode character, interval value of Uzz0000 to U+FFFFString character sequence Booleantrue or falseUnit means no value, which is the same as void in other languages. The result type used as a method that returns no results. Unit has only one instance value, written as (). The Nullnull or null reference NothingNothing type is at the lowest end of the class level of Scala; it is a subtype of any other type. AnyAny is the superclass of all other classes. The AnyRefAnyRef class is the base class of 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 types, and if you represent Long, you can add L or lowercase l after the number as a suffix. :

0

035

twenty-one

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 literals have true and false.

Symbolic literal quantity

The literal amount of the symbol is written as: 'here can be the logo of any letter or number (note: you cannot start with a number). This literal quantity is mapped to an instance of the predefined class scala.Symbol.

For example, the symbolic literal quantity'x is the abbreviation of the expression scala.Symbol ("x"). The symbolic literal quantity is defined as follows:

Package scala

Final case class Symbol private (name: String) {

Override def toString: String = "'" + name

}

Literal amount of characters

The character variable in Scala is defined in single quotation marks, as follows:

'a'

'\ u0041'

'\ n'

'\ t'

Where\ represents an escape character, which can be followed by a fixed escape character such as the u0041 number or\ r\ n.

String literals

Use double quotation marks to define the string variable in Scala, as follows:

"Hello,\ nWorld!"

The representation of the multiline string of "scala tutorial website: www.scala-lang.org"

The multiline string uses three double quotation marks to represent the delimiter in the format ".".

Examples are as follows:

Val foo = "" rookie tutorial

Www.runoob.com

Www.w3cschool.cc

Www.runnoob.com

The above three addresses can be accessed.

Null value

The null value is of type scala.Null.

Scala.Null and scala.Nothing are special types that handle some of the "boundary cases" of the Scala object-oriented type system in a unified way.

The Null class is a type of null reference object, which is a subclass of each reference class (a class that inherits from AnyRef). Null is not compatible with value types.

Scala escape character

The following table lists common escape characters:

Escape character Unicode description\ b\ u0008 backspace (BS), move the current position to the previous column\ t\ u0009 horizontal tabulation (HT) (skip to the next TAB position)\ n\ u000a line feed (LF), move the current position to the beginning of the next line\ f\ U000c page feed (FF), move the current position to the beginning of the next page\ r\ U000d enter (CR) Move the current position to the beginning of the line\ "\ u0022 represents a double quotation mark (") character\'\ u0027 represents a single quote (') character\\ u005c represents a backslash character

Unicode characters between 0 and 255 can be represented by an octal escape sequence, that is, the backslash "\" followed by up to three octets.

In a character or string, the backslash and the following character sequence cannot form a legal escape sequence will result in a compilation error.

The following examples demonstrate the use of some escape characters:

Object Test {

Def main (args: Array [String]) {

Println ("Hello\ tWorld\ n\ n")

}

}

The output of executing the above code is as follows:

$scalac Test.scala

$scala Test

Is it helpful for Hello World to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 217

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report