這是我的代碼: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!"}我收到一個(gè)錯(cuò)誤: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我應(yīng)該編輯IA界面還是修改我的A結(jié)構(gòu)?如果我在其他程序包中定義IA,IB(以便可以共享這些接口)怎么辦,我必須導(dǎo)入我的程序包并將IB用作A.FB()的返回類型,對(duì)嗎?
- 1 回答
- 0 關(guān)注
- 202 瀏覽
添加回答
舉報(bào)
0/150
提交
取消