go-tour/interfaces-are-satisfied-implicitly.go
2020-02-08 16:39:18 -06:00

23 lines
298 B
Go

package main
import "fmt"
type I interface {
M()
}
type T struct {
S string
}
// This method means type T implements the interface I,
// but we don't need to explicitly declare that it does so.
func (t T) M() {
fmt.Println(t.S)
}
func main() {
var i I = T{"hello"}
i.M()
}