golang反射

package main

import (
    "fmt"
    "reflect"
)

type Peaple struct {
}

func (p *Peaple) Eat() {

}
func (p *Peaple) Drink() {

}

func main() {
    a := new(Peaple)
    getType := reflect.TypeOf(a)
    getValue := reflect.ValueOf(a)

    fmt.Println(getType)
    fmt.Println(getValue)

    obj := reflect.Indirect(getValue).Type().Name()
    fmt.Println(obj)


    num := getType.NumMethod()
    fmt.Println(num)

    for i := 0; i < num; i++ {
        m := getType.Method(i)
        fmt.Println(obj + "." + m.Name)
    }
}

https://blog.csdn.net/raoxiaoya/article/details/109473904

golang反射

上一篇:Ansible Jinja2 模板


下一篇:SDRAM操作(FPGA实现)