July 2019
Intermediate to advanced
458 pages
12h 12m
English
In the same way that we can get reflect.Value from any interface{} value, we can execute the reverse operation and obtain interface{}from reflect.Value. This is done using the Interface method of the reflected value, and be cast to a concrete type if necessary. If the interested method or function accepts an empty interface, such as json.Marshal or fmt.Println, the returned value can be passed directly without any casting:
func main() { var a interface{} = int(12) v := reflect.ValueOf(a) fmt.Println(v.String()) fmt.Printf("%v", v.Interface())}A full example is available here: https://play.golang.org/p/1942Dhm5sap.
Read now
Unlock full access