不应明确返回长度为零的切片,而应该直接返回 nil 。 Bad Good return nil} 若要检查切片是否为空,始终使用 len(s) == 0 ,不要与 nil 比较来检查。 Bad Goodfunc isEmpty(s []string) bool {} 零值切片(通过 var 声明的切片)可直接使用,无需调用 make 创建。 Bad Goodif add1 {}if add2 { nums = append(nums, 2)