什么是“a”在这个函数?
func DPrintf(format string,a ...interface{}) (n int,err error) { if Debug > 0 { n,err = fmt.Printf(format,a...) } return
有谁能告诉我什么是点点在这里?
… interface {}做什么?
这个点阵点真的很难google,想知道他们的意思
谢谢!
The final parameter in a function signature may have a type prefixed with …. A function with such a parameter is called variadic and may be invoked with zero or more arguments for that parameter.
参数:
a ...interface{}
是,对于相当于的函数:
a []interface{}
不同的是如何传递参数到这样的函数。这是通过单独给出切片的每个片段或作为切片来完成的,在这种情况下,您将必须用三个点后缀切片值。以下示例将导致相同的调用:
fmt.Println("First","Second","Third")
会做同样的:
s := []interface{}{"First","Third"} fmt.Println(s...)
这在Go Specification也很好地解释:
Given the function and call
06004
within
Greeting
,who
will have the value[]string{"Joe","Anna","Eileen"}
If the final argument is assignable to a slice type []T,it may be passed unchanged as the value for a …T parameter if the argument is followed by …. In this case no new slice is created.
Given the slice
s
and call06005
within
Greeting
,who will have the same value as s with the same underlying array.