2015-11-13 97 views

回答

1

在調試你的代碼時,我到達了這個(仍然是壞的狀態),它清楚地顯示了你的實現有什麼問題; https://play.golang.org/p/MnyDxKvJsK

第二個鏈接已解決該問題。基本上,你的類型實際上並沒有實現接口,因爲你的返回類型。是的返回類型實現的接口,但它不是接口的實例。仔細看下面的代碼;

// 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