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) TypeParameters & Attributes
| Name | Type | Description |
|---|---|---|
| i | any | Input 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)) }