【发布时间】:2017-04-15 05:18:23
【问题描述】:
我试图通过将类型传递给函数来实现类型断言。换句话说,我正在尝试实现这样的目标:
// Note that this is pseudocode, because Type isn't the valid thing to use here
func myfunction(mystring string, mytype Type) {
...
someInterface := translate(mystring)
object, ok := someInterface.(mytype)
... // Do other stuff
}
func main() {
// What I want the function to be like
myfunction("hello world", map[string]string)
}
我需要在myfunction 中使用什么正确的函数声明才能成功执行myfunction 中的类型断言?
【问题讨论】:
标签: go type-conversion type-assertion