【发布时间】:2012-08-08 22:25:41
【问题描述】:
这是我的代码:
type IA interface {
FB() IB
}
type IB interface {
Bar() string
}
type A struct {
b *B
}
func (a *A) FB() *B {
return a.b
}
type B struct{}
func (b *B) Bar() string {
return "Bar!"
}
我收到一个错误:
cannot use a (type *A) as type IA in function argument:
*A does not implement IA (wrong type for FB method)
have FB() *B
want FB() IB
这里是完整代码:http://play.golang.org/p/udhsZgW3W2
我应该编辑 IA 接口还是修改我的 A 结构?
如果我在其他包中定义IA、IB(这样我可以共享这些接口),我必须导入我的包并将IB作为A.FB()的返回类型,对吗?
【问题讨论】: