Golang Reflect
一、反射获取类型对象与值
package main
import (
"fmt"
"reflect"
)
func main() {
a := 36
atype := reflect.TypeOf(a)
fmt.Println(atype.Name()) //获取类型名称为int
avalue := reflect.ValueOf(a)
fmt.Println(avalue.Int()) //获取具体的数值
}
二、反射获取结构体类型名称与类型
package main
import (
"fmt"
"reflect"
)
ty
Login required to read the rest of the content
登录 to comment~
Guess you like
Recommended articles