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
| Name | Type | Description |
|---|---|---|
| x | Value | New 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) }