How to cast reflect.Value to its type?

concreteCat,_ := reflect.ValueOf(cat).Interface().(Cat)

see http://golang.org/doc/articles/laws_of_reflection.html
fox example

type MyInt int
var x MyInt = 7
v := reflect.ValueOf(x)
y := v.Interface().(float64) // y will have type float64.
fmt.Println(y)

Leave a Comment