Kind in Go

Posted by GoDoc
Public (Editable by Users)

A Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.

Go
Edit
package main

import (
	"fmt"
	"reflect"
)

func main() {
	for _, v := range []interface{}{"hi", 42, func() {}} {
		switch v := reflect.ValueOf(v); v.Kind() {
		case reflect.String:
			fmt.Println(v.String())
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			fmt.Println(v.Int())
		default:
			fmt.Printf("unhandled kind %s", v.Kind())
		}
	}
}