Golang, Strcut contains interface types, the struct type needs to implement interface exported interfaces, thus becoming the corresponding interface interface classes.
In fact, after a struct contains interface, it does not need to implement the interface interface, or it can become a interface interface class.
The code is as follows:
Type newer interface {
new ()
}
T Ype TestInterface Interface {
newEr
done () <-chan struct{}
}
Type kktest struct {
testinterface
}
Func newtest () newer {
& Nbsp; return kktest{}
}
Func main () {
&NBSP;&NBSP;KK: = Newtest ()
i,ok: = Kk. ( TestInterface)
fmt. Println (I,ok)
ch: = I.done ()
fmt. PRINTLN (CH)
}
where I,ok: = Kk. ( TestInterface) test success, that is, Kktest is already the TestInterface interface class, but the subsequent ch: = I.done () raises panic, this is also expected.
Related applications can look at the implementation of the context package, VALUECTX partial implementation of the context interface function, to its unwanted functions are not implemented, if the call to these non-implemented functions will cause panic. This is a good thing to do in the wrong way, because calling to these interfaces means that the code is actually written incorrectly.