因为 map
是一个引用类型。有什么区别:?
m := make(map[string]int32)
和
m := map[string]int32{}
最佳答案
一个允许你初始化容量,一个允许你初始化值:
// Initializes a map with space for 15 items before reallocation
m := make(map[string]int32, 15)
对
// Initializes a map with an entry relating the name "bob" to the number 5
m := map[string]int{"bob": 5}
对于容量为 0 的空 map ,它们是相同的,只是偏好而已。
关于go - 初始化 map 的更好方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31064688/