Skip to content

Instantly share code, notes, and snippets.

@weiofcn
Created December 6, 2017 06:50
Show Gist options
  • Save weiofcn/4370cb066aa0419d9eb9c21a5e8b842d to your computer and use it in GitHub Desktop.
Save weiofcn/4370cb066aa0419d9eb9c21a5e8b842d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type I1 interface {
M1()
}
type I2 interface {
M2()
}
type T struct{}
func (T) M1() {
fmt.Println("T.M1")
}
func (T) M2() {
fmt.Println("T.M2")
}
func f1(i I1) {
i.M1()
}
func f2(i I2) {
i.M2()
}
func main() {
// 一个类型,可以实现多个接口
t := T{}
f1(t) // "T.M1"
f2(t) // "T.M2"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment