2021
06-04
06-04
golang 接口嵌套实现复用的操作
大家还是直接看代码吧~packagemainimport("fmt")funcmain(){start(NewB(C{}))start(NewB(D{}))}typeAinterface{what()}typeBstruct{A}typeCstruct{}func(bC)what(){fmt.Println("thisistypeC")}typeDstruct{}func(bD)what(){fmt.Println("thisistypeD")}funcstart(bB){b.what()}funcNewB(aA)B{returnB{a}}补充:【玩转Golang】通过组合嵌入实现代码复...
继续阅读 >