Go语言爱好者周刊:第 71 期

polaris · · 8578 次点击
struct的匿名成员而已, 不是什么bug. interface也可以是struct匿名成员. go官方库示例: [github.com/golang/go/src/sort](https://github.com/golang/go/blob/9b955d2d3fcff6a5bc8bce7bafdc4c634a28e95b/src/sort/sort.go#L239-L243) ```go // A type, typically a collection, that satisfies sort.Interface can be // sorted by the routines in this package. The methods require that the // elements of the collection be enumerated by an integer index. type Interface interface { // Len is the number of elements in the collection. Len() int // Less reports whether the element with // index i should sort before the element with index j. Less(i, j int) bool // Swap swaps the elements with indexes i and j. Swap(i, j int) } // ... type reverse struct { // This embedded Interface permits Reverse to use the methods of // another Interface implementation. Interface } ```
#9
更多评论
这道题确实比较奇葩, 我觉得应该算是go语言的一个bug. 能通过编译 但是因为没有定义work方法, 运行会报错. 这种应该编译期就阻止.
#1
这道题目是有点难度,我是怎么都没想到它能编译成功
#2