我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

无法将nil转换为x

Consider the following example:

    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()

The exceptions are as commented per line and i don't really get what i am doing wrong..

store is a map[int]Product

any ideas?

You are using store as if it were declared as:

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

近期文章

  • mongo-go-driver通过_id查找文档
  • FizzBu​​zz程序似乎很慢:为什么?
  • Golang PNG颜色处理不会达到255
  • 我可以进一步优化它,使其运行更快吗?
  • 为什么第5个字母是空格?
  • odi11g配置调度但是oracledi文件夹里面没有agent文件夹,求大神解决 着急!
  • thrift生成java文件报错
  • 请问adb源码怎么下载?
  • 虚拟机微信不能连续发送图片
  • C语言约瑟夫循环,不使用链表,依靠指针和循环实现?
  • 无法解决供应商目录中的依赖性
  • 是否可以在C / C ++中模仿Go接口?
  • 通过Golang访问JMX
  • Javascript websockets在打开后立即关闭
  • Cassandra的Golang客户端[关闭]
  • HTML5 <audio>标签的流容器
  • 去:没有哈希表(又名映射)的有效的字符串查找?
  • 如何在Golang中压缩包含子目录或文件的目录?
  • 为什么golang堆配置文件中的“总MB”比顶部的“ RES”小?
  • 如何为切片反射添加元素?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华