Go Package reflect

From NovaOrdis Knowledge Base
Revision as of 00:54, 22 August 2023 by Ovidiu (talk | contribs)
Jump to navigation Jump to search

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)) // will print 'int'
  fmt.Println(reflect.TypeOf(f)) // will print 'float64'
  fmt.Println(reflect.TypeOf(s)) // will print 'string'
}