文章目录
- GoLang之标准库reflect包
GoLang之标准库reflect包
本文基于Windos系统上Go SDK 1.8进行讲解
1.变量内在机制
2.反射介绍
3.Kind常量
4.TypeOf函数
5.ValueOf函数
6.Type接口
6.1Type接口
type Type interface {
Align() int
FieldAlign() int
Method(int) Method
MethodByName(string) (Method, bool)
NumMethod() int
Name() string
PkgPath() string
Size() uintptr
String() string
Kind() Kind
Implements(u Type) bool
AssignableTo(u Type) bool
ConvertibleTo(u Type) bool
Comparable() bool
Bits() int
ChanDir() ChanDir
IsVariadic() bool
Elem() Type
Field(i int) StructField
FieldByIndex(index []int) StructField
FieldByName(name string) (StructField, bool)
FieldByNameFunc(match func(string) bool) (StructField, bool)
In(i int) Type
Key() Type
Len() int
NumField() int
NumIn() int
NumOut() int
Out(i int) Type
common() *rtype
uncommon() *uncommonType
}
6.2Kind方法、Name方法
6.3NumMethod方法
6.4Method方法
6.5NumField方法
6.6Filed方法
6.7FieldByName方法
6.8FiledByIndex方法
7.Value结构体
7.1Value结构体
type Value struct {
typ *rtype
ptr unsafe.Pointer
flag
}
7.2IsNil方法、IsValid方法
7.3Int方法、float方法
7.4SetInt方法
7.5Elem方法
7.6NumMethod方法
7.7Method方法
7.8Call方法
7.9NumField方法
7.10Filed方法
7.11Interface方法
7.12FieldByName方法
7.13FieldByIndex方法
8.StructField结构体
8.1StructField结构体