package main
import (
"fmt"
"reflect"
)
type Dark interface {
Run(string)
Speak(string) string
}
type bird struct {
}
type chick struct {
}
func (c *chick) Run(msg string) {
fmt.Printf(msg)
}
func (c *chick) Speak() string {
return ""
}
func (b *bird) Run(msg string) {
fmt.Print(msg)
}
func (b *bird) Speak(string) string {
return ""
}
var (
//判断结构体bird是否实现了Dark接口
_ Dark = (*bird)(nil) //把nil转化成*bird类型 赋值后即丢弃
_ Dark = (*chick)(nil)//没有实现所有方法,所有编译报错
)
func main() {
var bird Dark = (*bird)(nil)
var chick Dark = (*chick)(nil)
fmt.Print(reflect.TypeOf(bird), reflect.TypeOf(chick))
}