- one type implements all methods of one interface => the type implement the interface
- every type has already implemented “interface{}”
- every type can be “wrapped in box” and “unpack the box” by using a “type assertion” and “type conversion” to interface which it has implemented
- in fact the type interface{}, which is called the empty interface type, is indispensable. Because the empty interface type places no demands on the types that satisfy it, we can assign any value to the empty interface --from TGPL
- type tySt struct {n int}, the type “*tySt” can use the mothods of type “tySt”, also in reverse. but *tySt contains *tySt and tySt mothod set, tySt only contain tySt mothod set when assigning to a interface, as well as “*tySt” and “tySt” can’t have the same name method, because implicit type-casting
- the empty interface “interface{}” includes “eface” structure, the non-empty interface has “iface” structure
golang-interface
最新推荐文章于 2022-05-17 11:39:35 发布