You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

reflect.go 438 B

2 years ago
2 years ago
1234567891011121314151617181920
  1. package reflect
  2. import "reflect"
  3. type Type = reflect.Type
  4. // TypeOfValue 获得实际值的类型
  5. func TypeOfValue(val any) reflect.Type {
  6. return reflect.TypeOf(val)
  7. }
  8. // TypeOf 获得泛型的类型
  9. func TypeOf[T any]() reflect.Type {
  10. return reflect.TypeOf([0]T{}).Elem()
  11. }
  12. // ElemTypeOf 获得泛型的类型。适用于数组、指针类型
  13. func ElemTypeOf[T any]() reflect.Type {
  14. return reflect.TypeOf([0]T{}).Elem().Elem()
  15. }

公共库

Contributors (1)