【发布时间】:2018-01-17 23:20:32
【问题描述】:
这是我的代码:
package main
import "fmt"
type Group struct {
}
func (g *Group) FooMethod() string {
return "foo"
}
type Data interface {
FooMethod() string
}
func NewJsonResponse(d Data) Data {
return d
}
func main() {
var g Group
json := NewJsonResponse(g)
fmt.Println("vim-go")
}
但没有按我的预期工作。
$ go build main.go
# command-line-arguments
./main.go:22: cannot use g (type Group) as type Data in argument to NewJsonResponse:
Group does not implement Data (FooMethod method has pointer receiver)
【问题讨论】:
-
查看Go, X does not implement Y (... method has a pointer receiver)了解详细解释和可能的解决方案。
标签: go