1
0
mirror of https://github.com/golang/go synced 2024-11-20 09:54:45 -07:00

reflect: reflect.Zero results are neither addressable nor settable

This could be deduced from "The Laws of Reflection" but it seems
worthwhile highlighting it.

R=r
CC=golang-dev
https://golang.org/cl/6350073
This commit is contained in:
Robert Griesemer 2012-07-03 16:06:24 -07:00
parent 1a0a09dafe
commit 6044dbdf1b

View File

@ -1713,10 +1713,11 @@ func ValueOf(i interface{}) Value {
return Value{typ, unsafe.Pointer(eface.word), fl}
}
// Zero returns a Value representing a zero value for the specified type.
// Zero returns a Value representing the zero value for the specified type.
// The result is different from the zero value of the Value struct,
// which represents no value at all.
// For example, Zero(TypeOf(42)) returns a Value with Kind Int and value 0.
// The returned value is neither addressable nor settable.
func Zero(typ Type) Value {
if typ == nil {
panic("reflect: Zero(nil)")