我期望在代码中使用 struct Dish被导出为 Dish。我预计当结构盘未导出并且看不到其中未导出的字段时,程序会失败。(好吧,我可以看到 EXPORTED STRUCTURE 中存在未导出的字段,但即使这样似乎也是错误的)。
但是程序仍然如图所示??如果未导出,反射包如何看到“dish”?
--------------Program Follows--------- //来自博客的修改示例:http : //merbist.com/2011/06/27/golang-reflection -示例/
package main
import (
"fmt"
"reflect"
)
func main() {
// iterate through the attributes of a Data Model instance
for name, mtype := range attributes(&dish{}) {
fmt.Printf("Name: %s, Type: %s\n", name, mtype)
}
}
// Data Model
type dish struct {
Id int
last string
Name string
Origin string
Query func()
}
// Example of how to use Go's reflection
// …Run Code Online (Sandbox Code Playgroud) 在对象或类上定义单例方法之前是否存在Eigenclasses.即当定义单例方法或类方法时,它们是否总是存在或存在?
我发现这是在Go书中,并且无法在语言的语法中找到它.有谁能解释一下?它本质上是某种"标签"吗?
return (<-reply).(int)
Run Code Online (Sandbox Code Playgroud)