type Animal struct {
Name string
LegCount int
}
snake := Animal{Name: "snake", LegCount: 0}
worm := Animal{Name: "worm"}
问题:我怎样才能检查snake
and worm
设置完毕后,告诉他们:
-
snake
被明确设置为LegCount
of 0.
- The
worm
's LegCount
没有明确设置(因此基于其默认值)?
根本无法区分。
如果要从 XML 或 JSON 解组数据,请使用指针。
type Animal struct {
Name *string
LegCount *int
}
你会得到nil
缺失字段的值。
您可以在您的情况下使用相同的约定。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)