Golang 中三个点...的作用

用法一:

为函数设置不定长度的参数

func myPrint(x ...interface{}) {
	for _, v := range x {
		fmt.Println(v)
	}
}

用法二:

为数组设置默认长度

a := [...]int{12, 32, 12}
// [12 32 12] 3 3 [3]int
fmt.Println(a, len(a), cap(a), reflect.TypeOf(a))

用法三:

append的时候用来打撒slice

a := []int{12, 23}
a = append(a, a...)
Aspire to inspire until I expire
原文地址:https://www.cnblogs.com/GetcharZp/p/15152338.html