jjzjj

FieldByIndex

全部标签

reflection - Go 反射(reflect)字段索引 - 单个索引与 slice

reflect.StructField有一个类型为[]int的Index字段。关于此的文档有点令人困惑:Index[]int//indexsequenceforType.FieldByIndex当然Type.FieldByIndex也符合预期,对其行为有更清晰的解释://FieldByIndexreturnsthenestedfieldcorresponding//totheindexsequence.ItisequivalenttocallingField//successivelyforeachindexi.//Itpanicsifthetype'sKindisnotStruct.