This is a creation in Article, where the information may have evolved or changed.
First on the code
Package Mainimport"FMT"type MyIntint//Anonymous Functions//the receive of the value//Receiving of pointers//*myint represents the pointer type of Myint//*i represents the pointer I, the value that points to IFunc (i *myint) Add (anotherint) myInt {*i = *i +MyInt (another)return*i}//I1 and I are two variables, passing valuesFunc Main () {i1:= MyInt (1) I2:= I1.add (2) fmt. Println (I1,I2)}
Value method, the pointer method follows the following rules:
The value represented by the recipient variable is actually a copy of the source value. If this value is not a pointer type, there is no way to change the source value in the value method.
The pointer value and its copy point to the same value, so there is a way to change the source value in the pointer method.
If the recipient type is a reference type or its alias type, even if it is a value method, you can change the source value
-------------
For a non-pointer data type, only its value method is included in the collection of methods associated with it. For its pointer type, the method collection contains only its value method, which also contains the pointer method.
On a value other than the pointer data type, it is also possible to invoke its pointer method.
This is because go has been automatically converted internally.
For example, if the Add method is a pointer method, the expression I1.add (2) is automatically converted to (&I1). Add (2)
The second rule is important for writing an implementation type for an interface type.