package main import ( "fmt" ) type A interface { Get() } type B struct { } func (b *B) Get () { fmt.Println("b") } type C struct { } func (c *C) Get () { fmt.Println("c") } func main() { var a A = &B{} a.Get() var aa A = &C{} aa.Get() }
输出结果:
b c
package main import ( "fmt" ) type A interface { Get() } type B struct { } func (b *B) Get () { fmt.Println("b") } type C struct { } func (c *C) Get () { fmt.Println("c") } func main() { var a A = &B{} a.Get() var aa A = &C{} aa.Get() }
输出结果:
b c