How to cast reflect.Value to its type?

后端 未结 4 1437
离开以前
离开以前 2021-01-31 07:50

How to cast reflect.Value to its type?

type Cat struct { 
    Age int
}

cat := reflect.ValueOf(obj)
fmt.Println(cat.Type()) // Cat

fmt.Println(Cat(cat).Age) //         


        
4条回答
  •  遥遥无期
    2021-01-31 08:38

    Ok, I found it

    reflect.Value has a function Interface() that converts it to interface{}

提交回复
热议问题