dsxgby126001 2015-06-26 04:03
浏览 38
已采纳

在Golang中初始化地图的更好方法是哪种? [重复]

This question already has an answer here:

As map is a reference type. What is difference between:?

m := make(map[string]int32)

and

m := map[string]int32{}
</div>
  • 写回答

1条回答 默认 最新

  • dporb84480 2015-06-26 04:08
    关注

    One allows you to initialize capacity, one allows you to initialize values:

    // Initializes a map with space for 15 items before reallocation
    m := make(map[string]int32, 15)
    

    vs

    // Initializes a map with an entry relating the name "bob" to the number 5
    m := map[string]int{"bob": 5} 
    

    For an empty map with capacity 0, they're the same and it's just preference.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?