Standard library / reflect

reflect.New()

Allocate a zero value of the specified type and return a reflected pointer to it. Its Elem is settable. Expected stdout: '7\n'.

Formal Syntax & Structure

go syntaxgo
func New(typ Type) Value

Parameters & Attributes

NameTypeDescription
typTypeRuntime type descriptor for the new value.

Return Value

Value

Allocate a zero value of the specified type and return a reflected pointer to it.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { v := reflect.New(reflect.TypeOf(0)); v.Elem().SetInt(7); fmt.Println(v.Elem().Int()) }
Go Reference