type Interface interface { Len() int Less(i, j int) bool Swap(i, j int) }
type reverse struct { Interface }
这段代码有大神可以解释一下么,看不懂
![]() |
1
zhujinliang 2018-02-26 17:34:54 +08:00 via iPhone ![]() 跟粘合一个结构体一样,相当于有个名叫 Interface 的字段,类型是 Interface
|
![]() |
2
rrfeng 2018-02-26 17:39:08 +08:00 ![]() type A struct{}
type B struct { A } 一样一样的 |
3
hanfengsmile OP ![]() @zhujinliang
@rrfeng 那这样写的好处是什么呢,看了 stackoverfloe 一个回答,没有理解 https://stackoverflow.com/questions/24537443/meaning-of-a-struct-with-embedded-anonymous-interface |