Source file tour/methods/interfaces-are-satisfied-implicitly.go
1 //go:build OMIT 2 3 package main 4 5 import "fmt" 6 7 type I interface { 8 M() 9 } 10 11 type T struct { 12 S string 13 } 14 15 // This method means type T implements the interface I, 16 // but we don't need to explicitly declare that it does so. 17 func (t T) M() { 18 fmt.Println(t.S) 19 } 20 21 func main() { 22 var i I = T{"hello"} 23 i.M() 24 } 25