In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to use the blank representation of the Go language", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use the blank representation of the Go language" article.
In the go language, it is illegal to import a package without using it in the code. When doing so, the compiler will report an error. The reason is to avoid importing too many unused packages, resulting in a significant increase in compilation time. The code is as follows:
Package main import ("geometry/rectangle" / / Import custom package) func main () {}
The above program will throw an error imported and not used: "geometry/rectangle"
However, in the active phase of program development, the package is often imported first and not used for the time being. In this case, you can use the blank identifier _.
The following code avoids errors in the above program:
Package mainimport ("geometry/rectangle") var _ = rectangle.Area / / error blocker func main () {}
The line var _ = rectangle.Area masks the error. We should understand the dynamics of these error blockers (Error Silencer) and remove them at the end of program development, including packages that have not yet been used. Therefore, it is recommended that you write error masks in the package-level range below the import statement.
Sometimes we import a package just to make sure it is initialized without using any functions or variables in the package. For example, we may need to make sure that the init function of the rectangle package is called and does not need to be used in the code. You can also use a blank identifier in this case, as shown below.
Package main import (_ "geometry/rectangle") func main () {}
Run the above program and you will output rectangle package initialized. Although we did not use this package in all the code, we successfully initialized it.
The above is the content of this article on "how to use blank representations in Go language". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
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.