In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly talks about "what are the types of GO language". 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 what are the types of GO language.
1. The type of the value provides the compiler with two parts of information: one is how much memory needs to be allocated to the value (that is, the size of the value); the other is what this memory represents.
2. There are two ways for user-defined types. One is to use the keyword struct to create a structural type, and the other is to use an existing type as a type description of the new type.
1)
Type admin struct {person user level String}
2)
Type Duration int64
3. There are three ways to create variables. One is to create a variable with the keyword var and initialize it to its zero value; the second is to match the structure literal ({}), and the third is to create a non-zero variable with the short variable declaration operator (: =).
4. Method: it is actually a function, and a parameter (receiver) is added between the keyword func and the method name when declared.
1) the receiver is divided into value receiver and pointer receiver.
2) (* lisa) .notify () the pointer variable lisa here is unindexed to a value. Because the recipient of the notify method is a value type. The recipient of the value of the method operates on a copy.
3) the value receiver uses a copy of the value to call the method, while the pointer receiver uses the actual value to call the method
4) (& bill) .changeEmail ("bill@newdomain.com") (& bill) refers to the pointer to the value, and the receiver of the changeEmail method is the pointer type.
5. The nature of the type
What is the nature of the type. If you add or delete a value to this type, do you want to create a new value, or do you want to change the current value? If you are creating a new value, this type of method uses the value receiver. If you want to modify the current value, use the pointer receiver.
1) built-in type
Primitive types are essentially provided by the language, including numeric, string, and Boolean types. Basic data values.
2) reference type
Slices, mappings, channels, interfaces, and function types. When a variable of the above type is declared, the variable created is called a header value. Values of reference types are treated in other ways like values of original data types
3) structural type
Used to describe a set of data values. Continue to look for information, do not quite understand.
6. Interface
1) Polymorphism refers to the ability of code to take different behaviors according to the specific implementation of the type.
2) "interface" is used to define the type of behavior. These defined behaviors are not implemented directly by the interface, but by user-defined types through methods. User-defined types are often called entity types.
3) meet the requirements of the implementation of the interface and the value of the user-defined type:
4) how user-defined type values are stored in the interface. There are two cases, the entity value is assigned to the interface, and the entity pointer is assigned to the interface.
5) method set: defines the accepted rules of the interface. A method set defines a set of methods associated with values or pointers of a given type.
6) the compiler does not always get the address of a value automatically, so the method set of values only includes methods implemented using the value receiver.
7) structure type type x struct {}, type x interface interface type, type x inter64 create new types based on existing types.
7. Embedding type
By embedding types, identifiers associated with internal types are promoted to external types. External types can also override fields or methods of internal identifiers by declaring an identifier with the same name as the internal type identifier. This is the way to extend or modify existing types.
8. Public or undisclosed identifiers
1) when the name of an identifier begins with a lowercase letter, the identifier is undisclosed, that is, the code outside the package is not visible. If an identifier begins with an uppercase letter, the identifier is public, that is, the code outside the package is visible.
2) when the code to be written belongs to a package, it is a good practice to use the same name as the folder where the code is located as the package name. All Go tools take advantage of this habit, so it's best to follow this good practice.
3) naming the factory function New is a habit of the Go language.
4) undisclosed types cannot be accessed directly. Unexposed embedded types cannot be accessed directly, such as exposed fields in unexposed embedded types, which can be promoted to parent types, so exposed fields in embedded classes can be accessed through exposed parent types.
At this point, I believe you have a deeper understanding of "what are the types of GO language". 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.