type Interface interface Len() int Less(i,j int) bool Swap(i,j int)}...type reverse struct Interface} ( ~8 w6 Y; c$ D) h
Interfacestruct匿名界面的含义是什么?reverse? : M; M, ^0 O3 `8 U6 V 4 ?4 h4 ?/ r5 p解决方案: , o# D6 w* ]) _: b1 v+ U; w 这样,反向实现sort.Interface,我们可以覆盖特定的方法而不必定义所有其他方法6 M+ D' v. R* p2 K$ W; B$ g
type reverse struct This embedded Interface permits Reverse to use the methods of another Interface implementation. Interface} * p8 y G; {$ a! Z, M6 F2 z
// Less returns the opposite of the embedded implementation's Less method.func (r reverse) Less(i,j int) bool return r.Interface.Less(j,i)} 4 c: }5 N/ L: ~