1
我不知道爲什麼下面的鑄造不起作用:去,因爲地圖[字符串]接口{}映射[字符串]字符串鑄鉛字失敗
import "fmt"
func main() {
v := map[string]interface{}{"hello": "world"}
checkCast(v)
}
func checkCast(v interface{}) {
_, isCorrectType := v.(map[string]string)
if !isCorrectType {
fmt.Printf("incorrect type") <------------- why does it enter this if statement?
return
}
}
有沒有辦法在Go中投射? – Karan
@Karan:看我修改後的答案。 Go有轉換。 – peterSO