摘要: // 多态 // 示例 package main import ( "fmt" ) type notifier interface { notify() } type user struct{ name string email string } func (u *user) notify(){ f 阅读全文
posted @ 2021-10-29 15:21 我在路上回头看 阅读(59) 评论(0) 推荐(0) 编辑
摘要: //从接收者类型的角度来看方法集 Methods Receivers Values (t T) T and *T (t *T) *T 如果使用指针接收者来实现一个接口,那么只有指向那个类型的指针才能够实现对应的接口。 如果使用值接收者来实现一个接口,那么那个类型的值和指针都能够实现对应的接口 // 阅读全文
posted @ 2021-10-29 15:11 我在路上回头看 阅读(49) 评论(0) 推荐(0) 编辑