Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go 无法将nil转换为x类型_Go - Fatal编程技术网

Go 无法将nil转换为x类型

Go 无法将nil转换为x类型,go,Go,考虑以下示例: 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.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]产品


有什么想法吗?

您使用的是
store
,就好像它被声明为:

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