Quick actions

cmd+k|ctrl+k

Navigation

Languages

Essential Go / Reflection

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:02:23Z

Updated

2019-03-26T10:02:23Z

package main

import (
	"fmt"
	"reflect"
)

func main() {
	var v interface{} = 4
	var reflectVal reflect.Value = reflect.ValueOf(v)

	var typ reflect.Type = reflectVal.Type()
	fmt.Printf("Type '%s' of size: %d bytes\n", typ.Name(), typ.Size())
	if typ.Kind() == reflect.Int {
		fmt.Printf("v contains value of type int\n")
	}
}
INFO