Go Package reflect: Difference between revisions
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
=<tt>reflect.TypeOf()</tt>= | =<tt>reflect.TypeOf()</tt>= | ||
=Getting the Type of Variable= | ==Getting the Type of Variable== | ||
<syntaxhighlight lang='go'> | <syntaxhighlight lang='go'> |
Revision as of 01:41, 28 December 2023
External
Internal
Overview
reflect.TypeOf()
Getting the Type of Variable
package main
import (
"fmt"
"reflect"
)
func main() {
i := 10
f := 10.1
s := "blue"
fmt.Println(reflect.TypeOf(i)) // returns a Type and will print 'int'
fmt.Println(reflect.TypeOf(f)) // returns a Type and will print 'float64'
fmt.Println(reflect.TypeOf(s)) // returns a Type and will print 'string'
}