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)
即可。
此处评论已关闭