Go:null judge

Go:null judge

null judge

int空值是0,

string空值是””而不是null或者nil(区别

Slice空值是长度为0的

map空值是nil,

error空值是nil,

struct空值是一个“所有成员都是空值”的空Struct而不是nil,

不能单纯地判断一个struct是不是nil,因为它永远不可能是nil,可以通过返回一个error来判断是否为空,

golang标准库里的常见做法:if err != nil

Author

Jack Liu

Posted on

2020-02-27

Updated on

2024-02-17

Licensed under