[Go] Types - Reflect.TypeOf()
Can use reflect.TypeOf
to get variable type
package main
import (
"fmt"
"reflect"
)
func main() {
// var age int = 21
// var b bool = age >= 23
var age = 21
var b = age >= 23
fmt.Println(reflect.TypeOf(age)) // int
fmt.Println(reflect.TypeOf(float64(age) * 5.5)) // float64
fmt.Println(reflect.TypeOf(b)) // bool
}
Can use type as constructor to convert a different type:
float64(age) * 5.5