gpt4 book ai didi

go - 无法将 nil 转换为类型 x

转载 作者:IT王子 更新时间:2023-10-29 01:19:36 25 4
gpt4 key购买 nike

考虑以下示例:

    lock.RLock()
var product *Product
if store[productId] != nil { //cannot convert nil to type Product
product = &Product{}
*product = *store[productId] //invalid indirect of store[productId] (type Product)
}
lock.RUnlock()

异常是每行注释的,我真的不明白我做错了什么..

store 是一个 map[int]Product

有什么想法吗?

最佳答案

您正在使用 store 就好像它被声明为:

store := make(map[int]*Product)

关于go - 无法将 nil 转换为类型 x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24719221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com