In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "Scala identifiers, naming and domain understanding", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to understand Scala identifiers, naming and domains.
In Scala, naming is used to represent types, values, methods, and classes, which are collectively referred to as entities. Naming exists in local definitions and declarations, inheritance, import clauses, and package clauses, which are collectively referred to as bindings.
Bindings have priority, definitions (partial or inheritance) have the highest priority, then explicit import, then the wildcard import, then package members, which is the lowest priority.
There are two different namespaces, one is a type and the other is a term. The same naming can represent a type or term, depending on the context in which the naming application is located.
The binding has a domain in which entities defined with a single name can be accessed with a simple name. Domains can be nested. Bindings in the internal domain will mask low-priority bindings in the same domain, or low-priority or equal-priority bindings in the external domain.
Note that masking is only a partial order. In the following cases:
Val x = 1
{import p.x
X}
The binding of x does not cover each other. So the meaning of the reference to x in the third line will be ambiguous.
A reference to an unqualified (type or term) identifier x can be singly bound under the following conditions:
L define an entity as an identifier with the name x in the same namespace
L masks all other entity bindings that define named x in this namespace
The absence of such a binding will result in an error. If x is bound by an import clause, then simply naming x will be equivalent to the naming qualified by the import clause mapping. If x is bound by a definition or declaration, then x refers to the entity introduced by that binding. In this case, the type of x is the type of the referenced entity.
Example 2.0.2 the following are the definitions of two objects named X in packages P and Q:
Package P {
Object X {val x = 1; val y = 2}
}
Package Q {
Object X {val x = true; val y = ""}
}
The following program shows the different bindings and priorities between them.
Package P {/ / "X" is bound by the package clause
Import Console._ / / "println" is bound by the wildcard character import
Object A {
Println ("L4:" + X) / / where "X" means "P.X"
Object B {
Import Q.{ / / "X" is bound by the wildcard import
Println ("L7:" + X) / / where "X" means "Q.X"
Import X. _ / / "x" and "y" are bound by the wildcard import
Println ("L8:" + x) / / where "x" means "Q.X.x"
Object C {
Val x = 3 / / "x" is bound by a local definition
Println ("L12:" + x) / / the "x" here means the constant "3"
{import Q.X._ / / "x" and "y" are bound by wildcard import
/ / println ("L14:" + x) / / the reference to "x" here is not clear
Import X.y / / "y" is bound by explicit import
Println ("L16:" + y) / / where "y" means "Q.X.y"
{val x = "abc" / / "x" is bound by a local definition
Import P.X. _ / / "x" and "y" are bound by the wildcard import
/ / println ("L19:" + y) / / the reference to "y" here is not clear
Println ("L20:" + x) / / where "x" refers to the string "abc"
}
A reference to the qualified (type or term) identifier e.x refers to a member named x of type T of e in the same namespace as an identifier. If T is not a value type, it will cause an error. The type of e.x is the type of the member of the referenced entity T.
At this point, I believe you have a deeper understanding of "Scala identifiers, naming and domain understanding". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.