panic: reflect.Value.Interface: cannot return value obtained from unexported field or method
来源:互联网 发布:怎么样抓取精准数据库 编辑:程序博客网 时间:2024/05/16 20:28
原文
go的反射reflect访问struct结构注意问题
type Point struct { X int Y string}func main() { po := Point{3, "ddd"} s := reflect.ValueOf(&po).Elem() for i := 0; i < s.NumField(); i++ { f := s.Field(i) fmt.Printf(" %s %v \n", f.Type(), f.Interface()) }}输出:int 3 string ddd
但是把Point里面X和Y改成小写的x,y;再执行程序的时候f.Interface会报错:
panic: reflect.Value.Interface: cannot return value obtained from unexported field or method
总结:
go语言里面struct里面变量如果大写则是public,如果是小写则是private的,private的时候通过反射不能获取其值
1 0
- panic: reflect.Value.Interface: cannot return value obtained from unexported field or method
- panic: reflect: reflect.Value.SetUint using value obtained using unexported field(go语言)
- panic: reflect: reflect.Value.SetUint using value obtained using unexported field(go语言)
- golang recover from panic situation: - reflect: call of reflect.Value.Elem on struct Value
- return confirm Cannot return from outside a function or method
- 关于MyEclipse较检异常 Invalid result location value/parameter 及Cannot return from outside a function or
- Cannot return from outside a function or method
- Cannot return from outside a function or method
- 【解决方法】Cannot return from outside a function or method
- myeclipse10:Cannot return from outside a function or method.
- Cannot return from outside a function or method
- Cannot return from outside a function or method
- Cannot return from outside a function or method
- Cannot return from outside a function or method
- “Cannot return from outside a function or method”
- BUG:Cannot return from outside a function or method
- 【报错】Cannot return from outside a function or method
- Myeclipse出现Cannot return from outside a function or method
- spark mllib Matrices CSC
- 求全排列的4种情况
- hdu5476 Explore Track of Point(数学)
- 阿里笔试题
- hdu5477 A Sweet Journey(水)
- panic: reflect.Value.Interface: cannot return value obtained from unexported field or method
- C++ TCP 和 UDP 在socket编程中的区别
- hdu5469 Antonidas(DFS)
- HHUOJ 1014 火眼金睛(另类思路题)
- 二进制dat格式数据转十六进制输出
- intel cpu
- XAMPP更改Apache的网站根目录
- 无影Shadowless-开源无线手柄设计
- 友录项目总结笔记: