亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

結構體即使功能相同也不實現接口

結構體即使功能相同也不實現接口

Go
米琪卡哇伊 2021-12-07 14:56:08
我不知道出現以下編譯錯誤的原因是什么。我將不勝感激任何幫助。./router.go:190: cannot use listener (type webhooklistener.MyListener) as type webhook.Listener in field value:    webhooklistener.MyListener does not implement webhook.Listener (missing webhook.handle method)        have webhooklistener.handle()        want webhook.handle()客戶:package webhooktype Listener interface {    handle()}type Client struct {    Listener Listener}聽眾:package webhooklistenertype MyListener struct {}func (ll MyListener) handle() {}路由器:listener := webhooklistener.MyListener{}client := webhook.Client{listener} // COMPILATION ERROR
查看完整描述

1 回答

?
回首憶惘然

TA貢獻1847條經驗 獲得超11個贊

webhook.Listener的 only 方法未導出,因此只有該包中的標識符才能實現它。如果希望其他包中的類型能夠實現它,則需要將其導出:


type Listener interface {

    Handle()

}


查看完整回答
反對 回復 2021-12-07
  • 1 回答
  • 0 關注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號