0x01 以下代码能通过编译吗
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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) 即可。
 
							











评论