Golang中的var()是什么意思

菲萨福尔:

我通过go-swagger生成的代码,发现以下代码:

// NewReceiveLearningLabActsParams creates a new ReceiveLearningLabActsParams object
// with the default values initialized.
func NewReceiveLearningLabActsParams() ReceiveLearningLabActsParams {
    var ()
    return ReceiveLearningLabActsParams{}
}

我在这里注意到:

var ()

我完全不知道这是什么意思,有人可以帮助我理解此代码吗?谢谢

马可:

在Go中,这是批量定义变量的简写。不必在每个变量声明前都写var,而可以使用var声明块。

例如:

var (
    a,b,c string = "this ", "is ","it "
    e,f,g int = 1, 2, 3
)

是相同的

var a,b,c string = "this ", "is ","it "
var d,e,f int = 1, 2, 3

var ()你的代码示例只是说,没有变量声明。

请参阅官方的Go文档以获取更多信息。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章