-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