The method of collection go Language Specification

Go Language Specification Rules method defined in set

Values        Methods Receivers
-----------------------------------------------
  T          (t T)
  *T          (t T) and (t *T)

T method of the type set of values ​​comprises a method declared value of the receiver only. And a pointer pointing to a method of the type T set value of both the recipient declaration contains the method, the method also includes pointers recipient declaration.

Type from the recipient's perspective methodologies

Methods Receivers   Values 
-----------------------------------------------
  (t T)         T and *T
  (t *T)         *T

If a recipient to implement an interface pointer, then only a pointer pointing to that type to be able to implement the corresponding interface. If the value of a receiver to implement the interface, then that type of pointer values ​​and the corresponding interface can be realized.

Guess you like

Origin www.cnblogs.com/c-x-a/p/11356213.html