In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "Scala Import clause example analysis". In daily operation, I believe many people have doubts about Scala Import clause example analysis. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Scala Import clause example analysis". Next, please follow the editor to study!
Syntax:
Import:: = "import" ImportExpr {"," ImportExpr}
ImportExpr:: = StableId "." (id | "_" | ImportSelectors)
ImportSelectors:: = "{" {ImportSelector ","} (ImportSelector | "_") "}"
ImportSelector:: = id ["= >" id | "= >" _ "]
The form of the import clause is import p. Iline p is a stability identifier (§3.1), and I is an import expression. The import expression determines a collection of names among the members of p, making them available unqualified. The most common form of import expression is a list of import selectors.
{x1 = > y1, … , xn= > yn,_}
Where n > = 0, the final wildcard "_" may not be left. It makes each member p.xi available under the unqualified name yi. For example, each import selector xi= > yi renames p.xi to yi. If there is a final wildcard, the member z of p other than x1,..., xn will also be available under its own unqualified name.
The import selector has the same effect on type and term members. For example, the import clause import p. {x = > y} renames the term p.x to the term y and renames the type name p.x to the type name y. At least one of these two names refers to a member of p.
If the target of the import selector is a wildcard, the import selector hides access to the source member. For example, the import selector x = > _ "renames" x to a wildcard symbol (inaccessible as a name in the user program), thus effectively preventing unrestricted access to x. This is useful when there is a wildcard at the end of the same import selector list, where all members not mentioned in the previous import selector are introduced.
The binding field introduced by the import clause begins after the import clause and extends to the end of the closure block, template, package clause, or compilation unit, depending on which appears first.
There are some simplified forms. The import selector can be just a name x. In this case, x is introduced without renaming, so the import selector is equivalent to x = > x. Further, you can replace the entire list of import selectors with an identifier or wildcard. The import clause import p. X is equivalent to import p. {x}, for example, without qualifying the member x of p. The import clause p. _ is equivalent to import p. {_}, for example, it is available without qualifying all members x of p (which is synonymous with import p. * in java).
Multiple import expressions import p1.I1, … in an import clause. Pn.In is interpreted as a sequence of import clauses import p1.I1; … ; import pn.In.
Example 4.7.1 consider the following object definitions:
Object M {
Def z = 0, one = 1
Def add (x: Int, y: Int): Int = x + y
}
So the code block
{import M. {one, z = > zero, _}; add (zero, one)}
It's equivalent to a code block.
{M.add (M.Z, M.one)}
At this point, the study of "Scala Import clause example analysis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.