我有這樣的事情:x1 := someFunctionWithAnInterfaceReturnValue()底層類型是這樣的:x2 := map[string] string{"hello": "world"}我將如何訪問 x1 中的值?本質上我想要 x1 的等價物: var value string = x2["hello"]
1 回答

海綿寶寶撒
TA貢獻1809條經驗 獲得超8個贊
使用類型斷言:
x1 := someFunctionWithAnInterfaceReturnValue()
x2, ok := x1.(map[string]string)
if !ok {
? ?// handle unexpected type
}
var value string = x2["hello"]
- 1 回答
- 0 關注
- 148 瀏覽
添加回答
舉報
0/150
提交
取消