The method set of a type determines the interfaces that the type implements and the methods that can be called using a receiver of that type.
- The method set of an interface type is its interface.
- The method set of any other type T consists of all methods declared with receiver type T.
- The method set of the corresponding pointer type *T is the set of all methods declared with receiver *T or T (that is, it also contains the method set of T).
Given a struct type S and a defined type T(anonymous field), promoted methods are included in the method set of the struct as follows:
- If S contains an embedded field T, the method sets of S and *S both include promoted methods with receiver T. The method set of *S also includes promoted methods with receiver *T.
- If S contains an embedded field *T, the method sets of S and *S both include promoted methods with receiver T or *T.
|sceneario||object value||object pointer|
|interface pointer method||no||yes|
|interface value method||yes||yes|
版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。