例如,在下面的例子:在Go中,类型和指向一个类型的指针都可以实现一个接口吗?
type Food interface {
Eat() bool
}
type vegetable_s struct {
//some data
}
type Vegetable *vegetable_s
type Salt struct {
// some data
}
func (p Vegetable) Eat() bool {
// some code
}
func (p Salt) Eat() bool {
// some code
}
做Vegetable
和Salt
既满足Food
,即使一个是一个指针,另一个是直接一个结构?
人知道为什么会设计这样的吗? –