【发布时间】:2017-08-15 20:29:22
【问题描述】:
我正在看 Go 的视频教程。我看到有一个类型声明和方法必须返回该类型的指针。
type testType struct {
value int
}
func (h *testType) testFunction(w http.ResponseWriter, r *http.Request) {
// we have empty body
}
如你所见,函数体是空的,没有返回语句。
- 为什么会编译?我不知道必须返回某些值的方法允许缺少“返回”指令。你能告诉我什么时候它们不是强制性的吗?
- 在这种情况下会返回什么值?总是零?
【问题讨论】:
标签: go