英文:
How to invoke methods with variant interface when you have array of interface?
问题
如何调用以下签名的方法:
SomeFunc(args ...interface{})
使用类型为[]interface{}
的变量,是否可以调用上述方法?如果可以,如何调用?
谢谢。
英文:
how to invoke a method with below signature
SomeFunc( args ...interface{})
with variable of type []interface{}
Is it possible to invoke the above method? If yes how?
Thanks
答案1
得分: 2
func main() {
b := []interface{}{"你好", "嗨"}
SomeFunc(b...)
}
通过在b数组后面使用...
解决了这个问题。
有关更多详细信息,请参见https://stackoverflow.com/questions/39914447/unpacking-slice-of-slices/39915311#39915311和https://stackoverflow.com/questions/36125024/golang-join-array-interface/36125119#36125119
英文:
func main() {
b := []interface{}{"hello", "Hi"}
SomeFunc(b...)
}
Solved the issue by using ...
after b array. <BR><BR>For more details plz see https://stackoverflow.com/questions/39914447/unpacking-slice-of-slices/39915311#39915311 and https://stackoverflow.com/questions/36125024/golang-join-array-interface/36125119#36125119
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论