So in the above code myObj.Fields is of type []*Field which needs to be assignable to []ider for the code to compile. Let's check wether that is the case. As one can read in https://golang.org/ref/spec#Assignability x的类型与T相同. x的类型V和T具有相同的基础类型,并且V或T中的至少一个不是命名类型. T是接口类型,并且x实现T. x是双向通道值,T是通道类型,x的类型V和T具有相同的元素类型,并且V或T中的至少一个不是命名类型. x是预声明的标识符nil,T是指针,函数,切片,映射,通道或接口类型. x是可由类型T的值表示的无类型常量. [] * Field 和 [] ider 是否相同? https://golang.org/ref/spec#Type_identity 告诉我们 * Field 和 ider 是否相同?上面的消息告诉我们So are *Field and ider identical?The above source tells us所以不行,因为 * Field 未命名,而 ider 被命名.So no and no, as *Field is unnamed and ider is named. [] * Field 的基础类型为 [] * Field , [] ider 的基础类型为 [] ider ,它们与我们在1中签到的不完全相同,因此也不适用.在此处阅读 https://golang.org/ref/spec#Types The underlying type of []*Field is []*Field and the underlying type of []ider is []ider, and those are not identical, as we checked in 1. so this is also not applicable. Read here https://golang.org/ref/spec#Types不适用,因为[] ider不是接口类型,而是切片类型.在此处阅读 https://golang.org/ref/spec#Slice_types is not applicable as []ider is not an interface type, but a slice type. Read here https://golang.org/ref/spec#Slice_types也不适用,因为没有使用通道also not applicable as there is no channel used也不适用,因为没有使用nil also not applicable as there is no nil used也不适用,因为没有使用常量.also not applicable as there is no constant used.所以总结: [] * Field 类型的值不能分配给 [] ider ,因此我们不能使用类型的表达式[] * Field 在参数位置参数类型为 [] ider 的函数调用的说明.So summing up: A value of type []*Field is not assignable to []ider and therefore we can't use an expression of type []*Field in a parameter positionof a function call with parameter type []ider. 这篇关于Go中特定接口的切片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-16 09:29