我试图通过将类型传入函数来实现类型断言。换句话说,我想实现这样的事情:Golang:将类型变量传入函数
// 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
执行类型说法对吗?
类型断言需要特定的类型。描述你正试图解决的更高层次的问题。什么是“做其他事情”? –