加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

golang:什么是字符串的零?

发布时间:2020-12-16 18:11:43 所属栏目:大数据 来源:网络整理
导读:func NewKey(c appengine.Context,kind,stringID string,intID int64,parent *Key) *Key 文档说: NewKey creates a new key. kind cannot be empty. Either one or both of stringID and intID must be zero . If both are zero,the key returned is incomp
func NewKey(c appengine.Context,kind,stringID string,intID int64,parent *Key) *Key

文档说:

NewKey creates a new key. kind cannot be empty. Either one or both of
stringID and intID must be zero. If both are zero,the key
returned is incomplete. parent must either be a complete key or nil.

字符串的零是什么?

我试过0和nil,我得到错误像:

cannot use nil as type string in function argument
那是 ”” :
var s string
fmt.Println(s=="") // prints "true"

字符串不能为nil(但是*字符串可以)。

你可以简单测试

if stringId=="" {

要在stringID中传递零字符串,请使用

k := NewKey(c,"kind","",p)

从the specification:

When memory is allocated to store a value,either through a
declaration or a call of make or new,and no explicit initialization
is provided,the memory is given a default initialization. Each
element of such a value is set to the zero value for its type: false
for booleans,0 for integers,0.0 for floats,“” for strings,and nil for pointers,functions,interfaces,slices,channels,and maps.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读