This is a creation in Article, where the information may have evolved or changed.
fornicated, come 10 sesame cakes ...
Package Mainimport"FMT"type Integerint//added new method for built-in int type less, object-oriented notationFunc (a integer) less (b integer)BOOL { returnA <b}func integer_less (a integer, b integer)BOOL { returnA <B}//Go object-oriented, if you need to modify the object, you must use the pointer, this is not a go constraint, or natural constraintsFunc (A *Integer) ADD (b Integer) {*a + =B}//The integer type is an int, an alias integer for int,//and added a series of methods Add,add2, and programmed a new type, which also fully has the function of int//passing values instead of pointersfunc (A integer) Add2 (b integer) {a+=FMT B. Println (a) fmt. Println (b)}func main () {varA Integer =1 ifA.less (2) {fmt. Println (A,"Less 2") } ifInteger_less (A,2) {fmt. Println (A,"Less 2") } //Add method is added to integer, and the Add () method needs to modify the value of the object, which requires a pointer reference//A.add (2)//FMT. Println ("A=", a)//the implementation member method is passed in if it is not a pointer, but a value, that is, an integer, not a *iteger, when a=1A.ADD2 (2) fmt. Println ("a=", a)//The go language, like the C language, is a type that is based on value passing, wants to modify the value of a variable, and can only pass pointers}/*There is no hidden this pointer method in the go language the target ("object") that is applied to the display is passed, and the target ("object") that is not applied by the hidden method does not need to be a pointer, nor does it have to be called this*/
Dairo said that the sesame cake was left at home
//value semantics and referential semantics//B=a//b.modify ()//If the modification of B does not affect the value of a, then this type is the value type//if the value of a is affected, then this type is the reference type//most of the go language types are value semantics//basic types: Byte, int, bool, float32, float64, string, etc.//composite types: array, struct (struct), and pointer (point)//the array is fully copied, which is the value semanticsFunc Main () {vara=[3]int{1,2,3}varB=a//represents a B=a assignment statement, which is a full copy of the array contentsb[1]++FMT. Println (A, b)}//reference method, you need to use pointersFunc Main () {varA = [3]int{1,2,3} varb = &a//This assignment is a reference to the array contents, and the variable B type is the *[3]int typeb[1]++FMT. Print (A,*b)}