Skip to content

Instantly share code, notes, and snippets.

@weiofcn
Last active December 6, 2017 06:51
Show Gist options
  • Save weiofcn/94af3be0a692097a7f31b76f0a6cb628 to your computer and use it in GitHub Desktop.
Save weiofcn/94af3be0a692097a7f31b76f0a6cb628 to your computer and use it in GitHub Desktop.
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