This is a creation in Article, where the information may have evolved or changed.
Package Mainimport ("FMT") type Animal interface {move ()}type Human struct {i int}func (R Human) Move () {//Note FMT. PRINTLN ("Human Walk") R.i++}type Bird struct {i int}func (R *bird) move () {fmt. Println ("Bird Walk") R.i++}func moveTest1 (animal animal) {animal.move ()}//Although the definition of this function is not wrong, it is actually completely useless! Because a pointer to an interface is in the interface implementation class, it is not possible to convert the Func moveTest2 (animal *animal) {(*animal). Move ()}func main () {h1: = Human{0}movetest1 (H1) MoveTest1 (H1) MoveTest1 (H1) fmt. Println (h1.i) fmt. Println ("----------------") H2: = &human{0}movetest1 (h2) MoveTest1 (H2) MoveTest1 (H2) fmt. Println (h2.i) fmt. Println ("----------------")//h3: = Human{0}//movetest2 (h3)//movetest2 (H3)//movetest2 (H3)//fmt. Println (h3.i)////fmt. Println ("----------------")//b1: = Bird{0}//movetest1 (B1)//movetest1 (B1)//movetest1 (B1)//fmt. Println (b1.i)////fmt. Println ("----------------") B2: = &bird{0}movetest1 (b2) moveTest1 (B2) moveTest1 (B2) fmt. Println (b2.i) fmt. Println ("----------------")//b3: = &bird{0}//movetest2 (b3)//movetest2 (b3)//movetest2 (b3)//fmt. Println (b3.i)////fmt. Println ("----------------")}
Human walking
Human walking
Human walking
0
----------------
Human walking
Human walking
Human walking
0
----------------
Birds walking
Birds walking
Birds walking
3
----------------
The above uses a simple explanation of the Golang in the use of the place to pay attention to.