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
}
Reflection lets your Go program inspect its own variables while they are running. Think of it like a label maker that tells you exactly what kind of box a value is sitting in, even if you didn't define that box yourself. You use this when writing generic code that needs to handle different data types dynamically.