
首先贴上 Go 开发团队对 reflect 包的描述:
Package reflect implements run-time reflection, allowing a program to manipulate objects with arbitrary types. The typical use is to take a value with static type interface{} and extract its dynamic type information by calling TypeOf, which returns a Type.
A call to ValueOf returns a Value representing the run-time data. Zero takes a Type and returns a Value representing a zero value for that type.
从描述中,我们得到以下几点:
- reflect 包实现了运行时的反射机制,允许程序操作任意类型的对象;
- TypeOf 可以得到一个 interface{} 的具体类型,ValueOf 可以得到一个 interface{} 的具体值;