Skip to content

Instantly share code, notes, and snippets.

@archever
Created September 21, 2018 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archever/c585a67e54e36ae9697dc66a76d2b637 to your computer and use it in GitHub Desktop.
Save archever/c585a67e54e36ae9697dc66a76d2b637 to your computer and use it in GitHub Desktop.
golang ... 可变参数并不是展开传递的
package main
import "log"
func test(data ...interface{}) {
for _, i := range data {
log.Printf("data: %v", i)
}
}
func main() {
a := []int{1, 2, 3, 4}
// cannot use a (type []int) as type []interface {} in argument to test
test(a...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment