Last active
December 6, 2017 06:51
-
-
Save weiofcn/94af3be0a692097a7f31b76f0a6cb628 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 I interface { | |
M() string | |
} | |
type T struct { | |
name string | |
} | |
func (t T) M() string { | |
return t.name | |
} | |
func Hello(i I) { | |
fmt.Printf("Hi, my name is %s \n", i.M()) | |
} | |
func main() { | |
//类型T满足接口I的定义。任何以T为类型的值,都可以传递给以I为参数的函数。 | |
Hello(T{name: "Golang"}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment