【发布时间】:2016-07-26 04:24:06
【问题描述】:
我发现了两个问题并阅读了它们:
但我仍然不明白为什么我尝试映射一个出错的对象:
./aaa.go:21: m.Action undefined (type interface {} is interface with no methods)
type MyStruct struct {
}
func (a *MyStruct) Action() {
fmt.Println("Hello")
}
func main() {
var Mstruct map[string]interface{}
Mstruct = make(map[string]interface{}, 100)
Mstruct["MyStruct"] = &MyStruct{}
m := Mstruct["MyStruct"]
fmt.Println(reflect.TypeOf(m)) // *main.MyStruct
m.Action()
}
这总是适用于动态语言,所以我错过了静态语言的一些东西。
【问题讨论】:
标签: go