func main(){
facestruct := new(FaceStruct)
facestruct.face = "testface"
var face interface{} = facestruct
if a, ok := face.(Face2); ok {
fmt.Printf("animal0 implement Animal interface!\n")
fmt.Println(a)
} else {
fmt.Printf("animal0 not implement Animal interface!\n")
}
}
type Face interface {
Method1() string
}
type Face2 interface {
Face
Method2() string
}
type FaceStruct struct {
face string
}
func (f *FaceStruct) Method1() string {
fmt.Println("Method1")
return "Method1"
}
func (f *FaceStruct) Method2() string {
return "Method2"
}
注意:
var face interface{} = facestruct 只能是interface{}