Standard library / reflect

reflect.Value.Set()

Assign another reflected value to a settable destination. The source type must be assignable, not merely convertible. Expected stdout: '8\n'.

Formal Syntax & Structure

go syntaxgo
func (v Value) Set(x Value)

Parameters & Attributes

NameTypeDescription
xValueNew value; must satisfy the destination kind or assignability requirement.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { n := 1; reflect.ValueOf(&n).Elem().Set(reflect.ValueOf(8)); fmt.Println(n) }
Go Reference