-1
是否使用字符串作为函数名称并调用它的方法?使用字符串作为函数名称 - golang
我有地图字符串的函数名
stuff := map[string]string{'keyword','function'}
和使用keyword
的时候,我想打电话给function
以2个参数
stuff['keyword'](arg1,arg2)
但它给我这个错误:
cannot call non-function key (type string)
有没有办法让我的string
到string
地图,仍然实现这一目标?
您可能需要[函数变量](https://stackoverflow.com/questions/3601796/can-we-have-function-pointers-in-google-go),而不是函数_names_。 – mustaccio
[Golang:从字符串(函数的名称)指向函数的指针](https://stackoverflow.com/questions/18017979/golang-pointer-to-function-from-string-functions-name) – eugenioy