考虑以下示例:
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
任何想法?
答案 0 :(得分:6)
您正在使用store
,就好像它被声明为:
store := make(map[int]*Product)