博學(xué)谷狂野大數(shù)據(jù)六期23年7月 學(xué)習(xí)筆記
2023-08-24 18:15 作者:bili_67158895267 | 我要投稿
golang中的多態(tài)是通過(guò)interface類型實(shí)現(xiàn)的
type Person interface { ?//接口Person規(guī)定了方法GetName
? ?GetName()}type Student struct {
? ?Name string
? ?Age ?int}func (this *Student) GetName() {
? ?fmt.Println(this.Name)}type Teacher struct {
? ?Name string
? ?Age ?int}func (this *Teacher) GetName() {
? ?fmt.Println(this.Name)}
標(biāo)簽: