Map nil
import ( "fmt")//panic: assignment to entry in nil maptype Param map[string]interface{}type Show struct { Param}func main() { s := new(Show) //s.Param["RMB"] = 10000 //panic: assignment to entry in nil map s.Param = map[string]interface{}{} s.Param = Param{} s.Param["RMB"] = 10000 fmt.Println(s)}
package mainimport "fmt"type Param map[string]interface{}type Show struct { *Param}func main() { s := new(Show) // s.Param["RMB"] = 10000 //invalid operation: s.Param["RMB"] (type *Param does not support indexing) p := Param{} s.Param = &p //s.Param["RMB"] = 100000 //s.Param["RMB"] (type *Param does not support indexing) (*s.Param)["RMB"] = 100000 fmt.Println(s.Param) }
给这篇文章的作者打赏
支付宝扫一扫打赏
×
打赏