package main
import (
"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}
}
golang 接口嵌套实现复用
最新推荐文章于 2024-07-05 08:45:00 发布