March 2020
Intermediate to advanced
406 pages
8h 39m
English
Values in reflection help to read, set, and store results on particular variables. In the following example, we can see that we set an example variable, foo, and, using the reflection package, we can deduce the value of our example variable in the resulting print statement as follows:
package mainimport ( "fmt" "reflect")func main() { example := "foo" exampleVal := reflect.ValueOf(example) fmt.Println(exampleVal)}
In our output, we can see that the value of the example variable, foo, gets returned:

These three different functions within the reflect system help us to deduce types that we can use within our code base.
Read now
Unlock full access