小编gil*_*lef的帖子

Go函数中定义的常量与包顶部定义的常量之间是否存在差异?

在函数范围内部和外部定义的常量之间是否存在差异(主要是性能)?

func (this *Person) SetDefaults() *Person{
    const (
        defaultFirstName = "first"
        defaultLastName  = "last"
    )

    //do stuff with constants
    return this
}
Run Code Online (Sandbox Code Playgroud)

与

const (
    defaultFirstName = "first"
    defaultLastName  = "last"
)
func (this *Person) SetDefaults() *Person{
    //do stuff with constants
    return this
}  
Run Code Online (Sandbox Code Playgroud)

constants go

2
推荐指数
1
解决办法
66
查看次数

标签 统计

constants ×1

go ×1