1 回答

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
在調(diào)試你的代碼時(shí),我到達(dá)了這個(gè)(仍然是損壞的狀態(tài)),它清楚地顯示了你的實(shí)現(xiàn)有什么問題;https://play.golang.org/p/MnyDxKvJsK
第二個(gè)鏈接已解決問題?;旧?,由于您的返回類型,您的類型實(shí)際上并沒有實(shí)現(xiàn)接口。是的,返回類型實(shí)現(xiàn)了接口,但它不是接口的實(shí)例。仔細(xì)看下面的代碼;
// your version *MyNestedStruct != MyNestedInterface
func (this *MyStruct) GetNested() *MyNestedStruct {
return this.nested
}
type MyInterface interface{
GetNested() MyNestedInterface
}
//my version
func (this *MyStruct) GetNested() MyNestedInterface {
return this.nested
}
https://play.golang.org/p/uf2FfvbATb
- 1 回答
- 0 關(guān)注
- 192 瀏覽
添加回答
舉報(bào)