Saturday 4 September 2021

Go Reflect

 Go Reflection is the ability of a program to examine its own structure, particularly through the types; it's a form of meta-programming.

Reflect can be used to investigate types and variables at runtime, e.g. its size, its methods, and it can also call these methods 'dynamically'.

Go Reflect example

  1. package main  
  2. import(  
  3.    "fmt"  
  4.    "reflect"  
  5. )  
  6. func main()  {  
  7.    age := 27.5  
  8.    fmt.Printf("%T\n" ,age)  
  9.    fmt.Println(reflect.TypeOf(age))  
  10. }  

Output:

float64
float64

No comments:

Post a Comment