GOLANG学习28. 反射
package main
import (
"fmt"
"reflect"
)
//结构体
type Student struct {
Name string
Age int
Score float32
}
//反射
func reflectTest(i interface{}) {
//类型 main.Student
t := reflect.TypeOf(i)
fmt.Println("reflect.TypeOf ", t)
//值 {zzs 30 88.8}
v := reflect.ValueOf(i)
fmt.Println(v)
//类别 struct
k := v.Kind()
fmt.Println(k)
}
func main() {
var stu Student = Student{
Name: "zzs",
Age: 30,
Score: 88.8,
}
reflectTest(stu)
}