golang 接口嵌套实现复用

来源:互联网 发布:无锡网络教育专升本 编辑:程序博客网 时间:2024/06/07 00:41
package mainimport (    "fmt")func main() {    start(NewB(C{}))    start(NewB(D{}))}type A interface {    what()}type B struct {    A}type C struct {}func (b C) what() {    fmt.Println("this is type C")}type D struct {}func (b D) what() {    fmt.Println("this is type D")}func start(b B) {    b.what()}func NewB(a A) B {    return B{a}}
原创粉丝点击