由于数字不能为,除非将返回值定义为指针,否则
nil无法返回
nil整数。Go中的惯用解决方案是定义您的方法以返回多个值,例如
func (s *stack) Pop() (int, bool) { //does not exists if ... { return 0, false } //... //v is the integer value return v, true}然后,什么地方可以拨打
Pop作为
s := &stack{}if v, ok := s.Pop(); ok { //the value exists}看看逗号吧,成语。



