Golang interface常见的坑
0x01 以下代码能通过编译吗
package main
import "fmt"
type user interface {
say(string)
}
type man struct{}
func (p *man) say(hello string) {
fmt.Println(hello)
}
func main() {
var u user = man{}
u.say("Hello World")
}不能通过编译,因为类型man没有实现user接口,实现say方法的是*man类型,两者不能统一。
把func (p *man) say(hello string) 改成func (p man) say(hello string) 即可。

