Created
December 6, 2017 06:50
-
-
Save weiofcn/4370cb066aa0419d9eb9c21a5e8b842d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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