【发布时间】:2016-08-21 12:34:09
【问题描述】:
我正在尝试将值分配给在 init func 中初始化的映射。
但是发生了恐慌: 分配给 nil 映射中的条目
package main
type Object interface {
}
type ObjectImpl struct {
}
type Test struct{
collection map[uint64] Object
}
func (test Test) init(){
test.collection = make(map[uint64] Object)
}
func main() {
test := &Test{}
test.init()
test.collection[1]=&ObjectImpl{}
}
【问题讨论】:
标签: dictionary go instantiation