我有一個實現接口的結構 - 因此我可以將該結構分配給所述接口的變量。但我想創建一個從 string -> Whoa 接口映射的類型,但在初始化時能夠使用具體的結構。這不起作用,我得到:不能使用 (map[string]Boom 文字) (map[string]Boom 類型的值) 作為變量聲明中的 poppa 值任何幫助表示贊賞!package maintype Whoa interface { yes()}type Boom struct { hey string}func (b Boom) yes() {}type poppa map[string]Whoafunc main() { var thisWorks Whoa = Boom{} var thisDoesnt poppa = map[string]Boom{}}
如何在 Golang 中使用接口與地圖?
慕婉清6462132
2022-10-17 17:14:05