type Animal struct {
Name string
LegCount int
}
snake := Animal{Name: "snake", LegCount: 0}
worm := Animal{Name: "worm"}问题:如何在设置了snake和worm之后检查它们,以说明这一点:
snake被显式设置为LegCount为0。worm的LegCount没有显式设置(因此是基于其默认值)?发布于 2016-03-15 14:40:42
这是根本无法区分的。
如果要从XML或JSON中解组数据,请使用指针。
type Animal struct {
Name *string
LegCount *int
}您将获得缺席字段的nil值。
在您的情况下,您可以使用相同的约定。
https://stackoverflow.com/questions/36014343
复制相似问题