今天面试被问到的,我答不上来,他问的是不是这两种写法的区别?
package main
import "fmt"
type Dog interface {
eat()
}
type dog struct{}
func (d dog) eat() {
fmt.Println("dog eat ...")
}
func dogEat1[T Dog](d T) {
d.eat()
}
func dogEat2(d Dog) {
d.eat()
}
func main() {
d := dog{}
dogEat1(d)
dogEat2(d)
}