#
When two or more consecutive named function parameters share a type, you can omit the type from all but the last.
In this example, we shortened
x int, y int
to
x, y int
代码
package main
import "fmt"
func add(x, y int) int {
return x + y
}
func main() {
fmt.Println(add(42, 13))
}
翻译
当你的函数(function)有多个参数,但是这几个参数的类型都一样的时候,你只需要在最后一个写上就行了
在这个例子当中
x int,y int
你可以这么写:
x,y int(这意思就是说x和y都是int类型)
总结
这个是Go提供的一个便利,但是感觉这么写会不会不太好看,后面看GO推荐的style吧
总结起来就是这么个事情
func argumentOmit(number int,count int,userName string,password string,pageSize int,pageNumber int,total int){
........具体内容
}
也可以写成:
func argumentOmit(number,count int,userName,password string,pageSize,pageNumber,total int){
........具体内容
}
注意只能修改连续,不连续的不能合并简写变量类型