go 结构体嵌套interface

running-fly / 2023-07-21 / 原文

package main

import "fmt"
//结构体嵌套接口,可以在结构体绑定的方法直接实现接口中的方法,直接调用接口中的方法
type aa interface{
	a()
	b()
}


type world struct{
	aa
	Age int
}
func(h world)a(){
	fmt.Println("hello a方法")
}
func(h world)b(){
	fmt.Println("hello b方法")
}

func main() {

 world:=world{}
 world.b() //输出 hello b方法

 

	
}