Standard library / reflect

reflect.Zero()

Construct a valid, non-settable zero value of a specified type. This is different from the invalid zero reflect.Value. Expected stdout: 'true 0 false\n'.

Formal Syntax & Structure

go syntaxgo
func Zero(typ Type) Value

Parameters & Attributes

NameTypeDescription
typTypeRuntime type descriptor for the new value.

Return Value

Value

Construct a valid, non-settable zero value of a specified type.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { v := reflect.Zero(reflect.TypeOf(42)); fmt.Println(v.IsValid(), v.Int(), v.CanSet()) }
Go Reference