funcs的零值

huangapple go评论70阅读模式
英文:

Zero value for funcs

问题

当你声明一个结构体 foo 时:

type foo struct {
  bar func(int) int
}

当你执行 var x foo 时,x.bar 的初始值是 nil

英文:

Given a struct:

type foo struct {
  bar func(int) int
}

when I var x foo

what is the initial value of x.bar ?

答案1

得分: 8

根据文档

> 未初始化的函数类型变量的值为nil。

英文:

From the documentation :

> The value of an uninitialized variable of function type is nil.

huangapple
  • 本文由 发表于 2015年4月9日 23:51:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/29543255.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定