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) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| typ | Type | Runtime 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()) }