Standard library / reflect

reflect.TypeOf()

Inspect the dynamic type of an interface value. A nil interface returns nil. Expected stdout: 'int\n'.

Formal Syntax & Structure

go syntaxgo
func TypeOf(i any) Type

Parameters & Attributes

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

Return Value

Type

Dynamic Type descriptor, or nil for a nil interface.

Working Example

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