How to Get the Type and Kind of a Value with Reflection

Get a value's type and kind at runtime using the reflect.TypeOf and reflect.ValueOf functions.

Use reflect.TypeOf to get the type and reflect.ValueOf to inspect the kind of a value at runtime.

package main

import (
	"fmt"
	"reflect"
)

func main() {
	var v interface{} = 42
	t := reflect.TypeOf(v)
	val := reflect.ValueOf(v)

	fmt.Println("Type:", t)   // int
	fmt.Println("Kind:", val.Kind()) // int
}