Standard library / reflect

reflect.ValueOf()

Wrap the dynamic value of an interface for inspection. Nil yields an invalid Value; ordinary values are not settable. Expected stdout: '42\n'.

Formal Syntax & Structure

go syntaxgo
func ValueOf(i any) Value

Parameters & Attributes

NameTypeDescription
ianyInput interface value; nil has no dynamic type or value.

Return Value

Value

Reflected Value, or the zero Value for nil.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { fmt.Println(reflect.ValueOf(42).Int()) }
Go Reference