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 are the scala data types

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what are the scala data types". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what scala data types are.

1.Scala programs are collections of objects that implement message delivery by calling each other's methods.

Objects-objects have properties and behaviors.

Class-A class is an abstraction of an object, and an object is a concrete instance of a class.

Method-the basic behavior described by a method, and a class can contain multiple methods.

Fields-each object has its unique collection of instance variables, that is, fields. The properties of the object are created by assigning values to the field.

The basic syntax of Scala should pay attention to the following points:

Case sensitive-Scala is case sensitive, which means that identifying Hello and hello have different meanings in Scala.

Class name-capitalize the first letter of all class names.

If you need to use several words to form the name of a class, the first letter of each word should be capitalized.

Method name-the first letter of all method names is lowercase.

If several words are used to form the name of a method, the first letter of each word should be capitalized.

Program file name-the name of the program file should exactly match the object name (recommended)

When you save a file, you should save the name of the object it uses (remember that Scala is case sensitive) and append ".scala" to the file extension. (if the file name and object name do not match, the program will not compile.)

Scala can use two forms of markers, characters, numbers and symbols.

2.Scala and Java have the same data type

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 Double32 bit of IEEE 754 standard unsigned Unicode character of IEEE 754 standard floating point number, Booleantrue or falseUnit of the character sequence from Uzz0000 to U+FFFFString 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.

3. In Scala, use the keyword "var" to declare variables and the keyword "val" to declare constants. The variable declaration must require an initial value, otherwise an error will be reported.

Scala supports the declaration of multiple variables

Val xmax, ymax = 100 / / xmax, ymax are all declared to be 100

If the return value of the method is a tuple, we can declare a tuple using val:

Scala > val pa = (40, "Foo")

4. Access modifier

The scala access modifier is basically the same as Java's: private,protected,public.

If no access modifier is specified, by default, the access level of the Scala object is public.

The private qualifier in Scala is stricter than Java. In the case of a nested class, the outer class cannot even access the private members of the nested class.

Private member

Decorated with the private keyword, members with this tag are visible only within the class or object that contains the member definition, and the same rules apply to inner classes.

Protect (Protected) members

In scala, access to Protected members is more stringent than java. Because it only allows protected members to be accessed in subclasses of the class in which the member is defined. In java, members modified with the protected keyword can be accessed not only by subclasses of the class that defines the member, but also by other classes in the same package.

Public member (public)

In Scala, if no modifier is specified, it defaults to public. Such members can be accessed anywhere.

5. Scope

In Scala, access modifiers can be emphasized by using qualifiers. The format is:

Private [x] or protected [x]

The x here refers to a package, class, or singleton object to which it belongs. If written as private [x], read as "this member is private to all classes except classes in […] or classes in […] packages and their concomitant objects.

Thank you for your reading, the above is the content of "what are the scala data types?" after the study of this article, I believe you have a deeper understanding of what the scala data type has, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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: 0

*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

Development

Wechat

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

12
Report