Go Package reflect: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 21: | Line 21: | ||
f := 10.1 | f := 10.1 | ||
s := "blue" | s := "blue" | ||
fmt.Println(reflect.TypeOf(i)) // will print 'int' | fmt.Println(reflect.TypeOf(i)) // returns a Type and will print 'int' | ||
fmt.Println(reflect.TypeOf(f)) // will print 'float64' | fmt.Println(reflect.TypeOf(f)) // returns a Type and will print 'float64' | ||
fmt.Println(reflect.TypeOf(s)) // will print 'string' | fmt.Println(reflect.TypeOf(s)) // returns a Type and will print 'string' | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 00:55, 22 August 2023
External
Internal
Overview
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'
}