如果我map[string]string在函數(shù)定義中聲明了返回值,是否需要在使用它之前就將其賦值,就像在函數(shù)體中聲明了它一樣?http://play.golang.org/p/iafZbG2ZbYpackage mainimport "fmt"func fill() (a_cool_map map[string]string) { // This fixes it: a_cool_map = make(map[string]string) a_cool_map["key"] = "value" return}func main() { a_cool_map := fill() fmt.Println(a_cool_map)}panic: runtime error: assignment to entry in nil map
- 1 回答
- 0 關(guān)注
- 206 瀏覽
添加回答
舉報(bào)
0/150
提交
取消